|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Filament\Resources; |
| 6 | + |
| 7 | +use App\Filament\Resources\SettingResource\Pages\CreateSetting; |
| 8 | +use App\Filament\Resources\SettingResource\Pages\EditSetting; |
| 9 | +use App\Filament\Resources\SettingResource\Pages\ListSettings; |
| 10 | +use App\Models\Setting; |
| 11 | +use Filament\Actions\BulkActionGroup; |
| 12 | +use Filament\Actions\DeleteBulkAction; |
| 13 | +use Filament\Actions\EditAction; |
| 14 | +use Filament\Forms\Components\Textarea; |
| 15 | +use Filament\Forms\Components\TextInput; |
| 16 | +use Filament\Forms\Components\Toggle; |
| 17 | +use Filament\Resources\Resource; |
| 18 | +use Filament\Schemas\Schema; |
| 19 | +use Filament\Tables\Columns\IconColumn; |
| 20 | +use Filament\Tables\Columns\TextColumn; |
| 21 | +use Filament\Tables\Table; |
| 22 | + |
| 23 | +class SettingResource extends Resource |
| 24 | +{ |
| 25 | + protected static ?string $model = Setting::class; |
| 26 | + |
| 27 | + protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-cog-6-tooth'; |
| 28 | + |
| 29 | + public static function getNavigationGroup(): ?string |
| 30 | + { |
| 31 | + return trans('setting.navigation_group'); |
| 32 | + } |
| 33 | + |
| 34 | + public static function getModelLabel(): string |
| 35 | + { |
| 36 | + return trans('setting.label'); |
| 37 | + } |
| 38 | + |
| 39 | + public static function getPluralModelLabel(): string |
| 40 | + { |
| 41 | + return trans('setting.plural_label'); |
| 42 | + } |
| 43 | + |
| 44 | + public static function form(Schema $schema): Schema |
| 45 | + { |
| 46 | + return $schema |
| 47 | + ->components([ |
| 48 | + TextInput::make('key') |
| 49 | + ->label(trans('setting.key')) |
| 50 | + ->required() |
| 51 | + ->maxLength(255) |
| 52 | + ->unique(Setting::class, 'key', ignoreRecord: true), |
| 53 | + TextInput::make('label') |
| 54 | + ->label(trans('setting.label_field')) |
| 55 | + ->maxLength(255), |
| 56 | + Toggle::make('autoload') |
| 57 | + ->label(trans('setting.autoload')) |
| 58 | + ->default(true), |
| 59 | + Textarea::make('content') |
| 60 | + ->label(trans('setting.content')) |
| 61 | + ->columnSpanFull(), |
| 62 | + ]); |
| 63 | + } |
| 64 | + |
| 65 | + public static function table(Table $table): Table |
| 66 | + { |
| 67 | + return $table |
| 68 | + ->defaultSort('created_at', 'desc') |
| 69 | + ->columns([ |
| 70 | + TextColumn::make('id') |
| 71 | + ->label('#') |
| 72 | + ->sortable(), |
| 73 | + TextColumn::make('key') |
| 74 | + ->label(trans('setting.key')) |
| 75 | + ->searchable(), |
| 76 | + TextColumn::make('label') |
| 77 | + ->label(trans('setting.label_field')) |
| 78 | + ->searchable() |
| 79 | + ->limit(30) |
| 80 | + ->wrap(), |
| 81 | + IconColumn::make('autoload') |
| 82 | + ->label(trans('setting.autoload')) |
| 83 | + ->boolean() |
| 84 | + ->sortable(), |
| 85 | + TextColumn::make('created_at') |
| 86 | + ->label(trans('setting.created_at')) |
| 87 | + ->dateTime() |
| 88 | + ->sortable() |
| 89 | + ->toggleable(isToggledHiddenByDefault: true), |
| 90 | + ]) |
| 91 | + ->filters([ |
| 92 | + // |
| 93 | + ]) |
| 94 | + ->recordActions([ |
| 95 | + EditAction::make(), |
| 96 | + ]) |
| 97 | + ->toolbarActions([ |
| 98 | + BulkActionGroup::make([ |
| 99 | + DeleteBulkAction::make(), |
| 100 | + ]), |
| 101 | + ]); |
| 102 | + } |
| 103 | + |
| 104 | + public static function getRelations(): array |
| 105 | + { |
| 106 | + return [ |
| 107 | + // |
| 108 | + ]; |
| 109 | + } |
| 110 | + |
| 111 | + public static function getPages(): array |
| 112 | + { |
| 113 | + return [ |
| 114 | + 'index' => ListSettings::route('/'), |
| 115 | + 'create' => CreateSetting::route('/create'), |
| 116 | + 'edit' => EditSetting::route('/{record}/edit'), |
| 117 | + ]; |
| 118 | + } |
| 119 | +} |
0 commit comments