getKeyName(); } public static function getRecordTitleAttribute(): string { return (new static::$model)->getKeyName(); } public static function table(Table $table): Table { return $table ->defaultSort(fn (Table $table): ?string => $table->hasSearch() ? null : static::getRecordRouteKeyName(), fn (Table $table): ?string => $table->hasSearch() ? null : 'desc') ->filters(static::getFilters()) ->filtersLayout(FiltersLayout::Modal) ->filtersFormWidth(Width::FourExtraLarge) ->filtersFormMaxHeight('400px') ->recordActions(static::getActions()) ->toolbarActions(static::getBulkActions()) ->headerActions(static::getTableActions()) ->recordUrl(fn (Model $record): string => static::getUrl('view', ['record' => $record])) ->paginated([10, 25, 50, 100, 'all']) ->defaultPaginationPageOption(25) ->extremePaginationLinks() ->deferLoading(! app()->runningUnitTests()); } /** * @return \Filament\Tables\Filters\BaseFilter[] */ public static function getFilters(): array { return [ TrashedFilter::make() ->visible(in_array(SoftDeletable::class, class_implements(static::getModel()))), ]; } /** * @return Constraint[] */ public static function getConstraints(): array { return [ DateConstraint::make(BaseModel::ATTRIBUTE_CREATED_AT) ->label(__('filament.fields.base.created_at')), DateConstraint::make(BaseModel::ATTRIBUTE_UPDATED_AT) ->label(__('filament.fields.base.updated_at')), ]; } /** * @return array */ public static function getActions(): array { return [ ...(Gate::allows('viewAny', static::$model) ? [ViewAction::make()] : []), ...(Gate::allows('updateAny', static::$model) ? [EditAction::make()] : []), ActionGroup::make([ DetachAction::make(), ...(Gate::allows('deleteAny', static::$model) ? [DeleteAction::make()] : []), ...(Gate::allows('forceDeleteAny', static::$model) ? [ForceDeleteAction::make()] : []), ...(Gate::allows('restoreAny', static::$model) ? [RestoreAction::make()] : []), ...(Gate::allows('create', static::$model) ? [ReplicateAction::make()] : []), ActionGroup::make(static::getRecordActions())->dropdown(false), ]), ]; } /** * @return Action[] */ public static function getRecordActions(): array { return []; } /** * @param array|null $actionsIncludedInGroup * @return array */ public static function getBulkActions(?array $actionsIncludedInGroup = []): array { return [ BulkActionGroup::make([ ...(Gate::allows('deleteAny', static::$model) ? [DeleteBulkAction::make()] : []), ...(Gate::allows('forceDeleteAny', static::$model) ? [ForceDeleteBulkAction::make()] : []), ...(Gate::allows('restoreAny', static::$model) ? [RestoreBulkAction::make()] : []), ...$actionsIncludedInGroup, ]), ]; } /** * @return array */ public static function getTableActions(): array { return []; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } /** * @return array> */ public static function getBaseRelations(): array { return [ ActivityRelationManager::class, AuditsRelationManager::class, ]; } public static function getSlug(?Panel $panel = null): string { return 'resources/'.static::getRecordSlug(); } abstract public static function getRecordSlug(): string; }