{{-- Reusable permission selector for the role create/edit forms. Expects: - $permissions : Collection<\Spatie\Permission\Models\Permission> (all permissions) - $role : \Spatie\Permission\Models\Role|null (null on create) Permissions are grouped by module via App\Authorization\Permissions::groups() (the single source of truth). Any permission not listed in a group is rendered under "Other" so custom/legacy permissions stay assignable. Currently-assigned permissions (or old() input after a validation error) are pre-checked. --}} @php use App\Authorization\Permissions; $role = $role ?? null; $byName = $permissions->keyBy('name'); $assigned = collect(old('permissions', $role ? $role->permissions->pluck('name')->all() : [])); $groups = collect(Permissions::groups()); $grouped = $groups->flatten()->all(); $others = $permissions->reject(fn ($p) => in_array($p->name, $grouped, true)); @endphp
@foreach ($groups as $label => $names) @php($items = collect($names)->map(fn ($name) => $byName->get($name))->filter()) @if ($items->isNotEmpty())
{{ $label }}
@foreach ($items as $permission)
@endforeach
@endif @endforeach @if ($others->isNotEmpty())
Other
@foreach ($others as $permission)
@endforeach
@endif
@error('permissions') {{ $message }} @enderror