add badge logic

This commit is contained in:
root
2026-04-25 01:23:21 -04:00
parent eafe4eb134
commit 5c544f93b9
13 changed files with 1468 additions and 169 deletions
@@ -149,6 +149,7 @@ class BadgeController extends Controller
'data' => $this->badgeFormDataService->build(
schoolYear: $request->input('school_year'),
selectedUserIds: $this->parseStaffUserIds($request),
selectedStudentIds: $this->parseStudentIds($request),
activeRole: $request->input('active_role')
),
]);
+25 -3
View File
@@ -3,6 +3,7 @@
namespace App\Http\Requests\Roles;
use App\Http\Requests\ApiFormRequest;
use App\Models\Role;
use Illuminate\Validation\Rule;
class RoleUpdateRequest extends ApiFormRequest
@@ -14,11 +15,32 @@ class RoleUpdateRequest extends ApiFormRequest
public function rules(): array
{
$roleId = (int) $this->route('roleId');
$roleId = (int) (
$this->route('roleId')
?? $this->route('id')
?? $this->input('id')
?? 0
);
$current = $roleId > 0 ? Role::query()->find($roleId) : null;
$currentName = strtolower(trim((string) ($current?->name ?? '')));
$currentSlug = strtolower(trim((string) ($current?->slug ?? '')));
$incomingName = strtolower(trim((string) $this->input('name', '')));
$incomingSlug = strtolower(trim((string) $this->input('slug', '')));
$nameRules = ['sometimes', 'string', 'min:3', 'max:255'];
if ($incomingName !== '' && $incomingName !== $currentName) {
$nameRules[] = Rule::unique('roles', 'name')->ignore($roleId);
}
$slugRules = ['nullable', 'string', 'max:64'];
if ($incomingSlug !== '' && $incomingSlug !== $currentSlug) {
$slugRules[] = Rule::unique('roles', 'slug')->ignore($roleId);
}
return [
'name' => ['sometimes', 'string', 'min:3', 'max:255', Rule::unique('roles', 'name')->ignore($roleId)],
'slug' => ['nullable', 'string', 'max:64', Rule::unique('roles', 'slug')->ignore($roleId)],
'name' => $nameRules,
'slug' => $slugRules,
'description' => ['nullable', 'string', 'max:500'],
'dashboard_route' => ['sometimes', 'string', 'min:1', 'max:255', 'regex:/^[a-z0-9_\\/\\-]+$/'],
'priority' => ['sometimes', 'integer', 'min:0', 'max:100000'],
@@ -9,14 +9,14 @@ class RolePermissionResource extends JsonResource
public function toArray($request): array
{
return [
'permission_id' => (int) ($this['id'] ?? $this['permission_id'] ?? 0),
'name' => (string) ($this['name'] ?? ''),
'description' => $this['description'] ?? null,
'can_create' => (int) ($this['can_create'] ?? 0),
'can_read' => (int) ($this['can_read'] ?? 0),
'can_update' => (int) ($this['can_update'] ?? 0),
'can_delete' => (int) ($this['can_delete'] ?? 0),
'can_manage' => (int) ($this['can_manage'] ?? 0),
'permission_id' => (int) ($this->id ?? $this->permission_id ?? $this['id'] ?? $this['permission_id'] ?? 0),
'name' => (string) ($this->name ?? $this['name'] ?? ''),
'description' => $this->description ?? $this['description'] ?? null,
'can_create' => (int) ($this->can_create ?? $this['can_create'] ?? 0),
'can_read' => (int) ($this->can_read ?? $this['can_read'] ?? 0),
'can_update' => (int) ($this->can_update ?? $this['can_update'] ?? 0),
'can_delete' => (int) ($this->can_delete ?? $this['can_delete'] ?? 0),
'can_manage' => (int) ($this->can_manage ?? $this['can_manage'] ?? 0),
];
}
}