@extends('layouts.layoutMaster') @section('title', ($model->id ? 'Update' : 'Create') . ' Role') @php use Illuminate\Support\Str; $m = 'App\\Models\\Role'; $labels = Helper::getModelLabels($m); $breadcrumbs = [ ['url' => route('dashboard'), 'label' => 'Dashboard'], ['url' => route('role.index'), 'label' => 'Role'], ]; if ($model->id) { $breadcrumbs[] = [ 'url' => route('role.show', ['role' => $model->id]), 'label' => $model->name, ]; $breadcrumbs[] = [ 'url' => route('role.edit', ['role' => $model->id]), 'label' => 'Update Role', ]; } else { $breadcrumbs[] = [ 'url' => route('role.create'), 'label' => 'Create Role', ]; } // Get existing permissions for the role $existingPermissions = $model->id ? $model->permissions->pluck('name')->toArray() : []; @endphp @section('content')
{{ $model->id ? 'Edit' : 'New' }} Role
@csrf @if ($model->id) @method('PUT') @endif
@error('name')
{{ $message }}
@enderror
Basic Permission
@foreach ($permissions as $resourceLabel => $resourcePermissions) @php // Create a map of permissions by key for easy lookup $permissionMap = collect($resourcePermissions)->keyBy('key'); $standardActions = ['index', 'show', 'create', 'update', 'destroy']; @endphp @foreach ($standardActions as $actionKey) @if ($permissionMap->has($actionKey)) @php $permission = $permissionMap[$actionKey]; $isChecked = false; foreach ($permission['actual_permissions'] as $actualPerm) { if (in_array($actualPerm, $existingPermissions)) { $isChecked = true; break; } } $checkboxId = 'permission-' . str_replace( ['.', '-'], '_', $permission['resource_key'] . '-' . $permission['key'], ); @endphp @else @endif @endforeach @endforeach
Module
Custom Permission
@foreach ($permissions as $resourceLabel => $resourcePermissions) @php $permission = $resourcePermissions[0] ?? null; $resourceKey = $permission['resource_key'] ?? Str::slug($resourceLabel); $existingCustom = $customPermissions[$resourceKey] ?? []; @endphp @if (!empty($existingCustom)) @endif @endforeach
Module Custom Actions
@foreach ($existingCustom as $customPerm) @php $customCheckboxId = 'custom-' . str_replace('.', '-', $customPerm['name']); $isCustomChecked = in_array( $customPerm['name'], $existingPermissions, ); @endphp
@endforeach
@error('permissions')
{{ $message }}
@enderror
Cancel
@endsection @section('page-script') @endsection