setPrimaryKey('id') ->setDefaultSort('name', 'asc') ->setSortingPillsEnabled(false); } public function builder(): Builder { return Role::withCount(['permissions', 'users']); } public function columns(): array { return [ Column::make(__('Name'), 'name') ->sortable() ->searchable() ->format(fn ($value, $row) => ''.e($value).'' . (in_array($row->name, self::PROTECTED_ROLES, true) ? ' protegido' : '') ) ->html(), Column::make(__('Description'), 'description') ->sortable() ->searchable() ->format(fn ($value) => $value ? ''.e($value).'' : '') ->html(), Column::make(__('Permissions')) ->label(fn ($row) => ''.(int) $row->permissions_count.'') ->html(), Column::make(__('Users')) ->label(fn ($row) => ''.(int) $row->users_count.'') ->html(), Column::make(__('Actions')) ->label(function ($row) { $show = route('admin.roles.show', $row->id); $edit = route('admin.roles.edit', $row->id); $eye = ''; $pencil = ''; $trash = ''; $html = '
'; $html .= ''.$eye.''; $html .= ''.$pencil.''; if (! in_array($row->name, self::PROTECTED_ROLES, true)) { $html .= ''; } $html .= '
'; return $html; }) ->html(), ]; } public function bulkActions(): array { return ['bulkDelete' => __('Delete selected')]; } public function bulkDelete(): void { $roles = Role::whereIn('id', $this->selected)->get(); foreach ($roles as $role) { if (in_array($role->name, self::PROTECTED_ROLES, true)) continue; $role->delete(); } $this->clearSelected(); app(PermissionRegistrar::class)->forgetCachedPermissions(); $this->dispatch('notify', __('Roles deleted')); } public function deleteRole(int $id): void { $role = Role::findOrFail($id); if (in_array($role->name, self::PROTECTED_ROLES, true)) { return; } $role->delete(); app(PermissionRegistrar::class)->forgetCachedPermissions(); $this->dispatch('notify', __('Role deleted')); } }