@php $selectedPermissions = collect(old('permissions', $role->permissions->pluck('id')->all())); $grouped = $permissions->groupBy('group'); $actions = collect(['view', 'create', 'update']); @endphp
@foreach($grouped as $group => $items) @php $itemByAction = $items->keyBy(fn($permission) => \Illuminate\Support\Str::afterLast($permission->slug, '.')); @endphp
{{ $group ?? 'General' }}
@foreach($actions as $action) @php $allChecked = $items->filter(fn($permission) => \Illuminate\Support\Str::endsWith($permission->slug, '.' . $action)) ->pluck('id') ->every(fn($id) => $selectedPermissions->contains($id)); @endphp @endforeach
@foreach($items->groupBy(function($permission) { // For permissions like "issues.history.view", extract "issues.history" // For permissions like "issues.view", extract "issues" $parts = explode('.', $permission->slug); // Remove the last part (action) and join the rest array_pop($parts); return implode('.', $parts); }) as $moduleSlug => $modulePermissions)

{{ \Illuminate\Support\Str::headline($moduleSlug ?? ($group ?? 'General')) }}

@foreach($actions as $action) @php($permission = $modulePermissions->first(fn($p) => \Illuminate\Support\Str::endsWith($p->slug, '.' . $action)))
@if($permission) contains($permission->id))> @if($permission->description) {{ $permission->description }} @endif @else {{ ucfirst($action) }} not applicable @endif
@endforeach
@endforeach
@endforeach
Cancel
@push('scripts') @endpush