schema([ Forms\Components\Section::make('اطلاعات نقش') ->schema([ Forms\Components\TextInput::make('name') ->label('نام نقش (انگلیسی)') ->required() ->unique(ignoreRecord: true) ->maxLength(255), Forms\Components\Select::make('guard_name') ->label('نوع Guard') ->options([ 'web' => 'Web', 'api' => 'API', ]) ->default('web') ->required(), ])->columns(2), Forms\Components\Section::make('دسترسی‌ها') ->schema([ Forms\Components\CheckboxList::make('permissions') ->label('دسترسی‌های این نقش') ->relationship('permissions', 'name') ->columns(3) ->bulkToggleable(), ]), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('شناسه') ->sortable(), Tables\Columns\TextColumn::make('name') ->label('نام') ->searchable() ->sortable() ->badge() ->color(fn (string $state): string => match ($state) { 'super_admin' => 'danger', 'admin' => 'warning', 'staff' => 'info', 'customer' => 'success', default => 'gray', }), Tables\Columns\TextColumn::make('guard_name') ->label('Guard') ->badge() ->color('gray'), Tables\Columns\TextColumn::make('users_count') ->label('تعداد کاربران') ->counts('users') ->badge() ->color('info'), Tables\Columns\TextColumn::make('permissions_count') ->label('تعداد دسترسی‌ها') ->counts('permissions') ->badge() ->color('success'), Tables\Columns\TextColumn::make('created_at') ->label('تاریخ ایجاد') ->dateTime('Y/m/d') ->sortable(), ]) ->filters([]) ->actions([ Tables\Actions\EditAction::make()->label('ویرایش'), Tables\Actions\DeleteAction::make()->label('حذف'), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->defaultSort('created_at', 'desc'); } public static function getRelations(): array { return []; } public static function getPages(): array { return [ 'index' => Pages\ListRoles::route('/'), 'create' => Pages\CreateRole::route('/create'), 'edit' => Pages\EditRole::route('/{record}/edit'), ]; } // ... بقیه کد فعلی (form, table, getPages) ... // ─── Access Control (فقط super_admin) ─── protected static function getCurrentUser(): ?\App\Models\User { $user = Auth::user(); return $user instanceof \App\Models\User ? $user : null; } public static function canViewAny(): bool { $user = static::getCurrentUser(); return $user !== null && $user->hasRole('super_admin'); } public static function canCreate(): bool { return static::canViewAny(); } public static function canEdit($record): bool { return static::canViewAny(); } public static function canDelete($record): bool { // جلوگیری از حذف نقش super_admin حتی توسط super_admin if ($record->name === 'super_admin') { return false; } return static::canViewAny(); } }