|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tapp\FilamentLibrary\Resources; |
| 4 | + |
| 5 | +use Filament\Resources\Resource; |
| 6 | +use Filament\Schemas\Schema; |
| 7 | +use Filament\Tables; |
| 8 | +use Filament\Tables\Table; |
| 9 | +use Tapp\FilamentLibrary\Models\LibraryItem; |
| 10 | + |
| 11 | +class LibraryItemResource extends Resource |
| 12 | +{ |
| 13 | + protected static ?string $model = LibraryItem::class; |
| 14 | + |
| 15 | + protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-folder'; |
| 16 | + |
| 17 | + protected static string|\UnitEnum|null $navigationGroup = 'Library'; |
| 18 | + |
| 19 | + protected static ?int $navigationSort = 10; |
| 20 | + |
| 21 | + protected static ?string $navigationLabel = 'Library'; |
| 22 | + |
| 23 | + protected static ?string $modelLabel = 'Library Item'; |
| 24 | + |
| 25 | + protected static ?string $pluralModelLabel = 'Library Items'; |
| 26 | + |
| 27 | + public static function form(Schema $schema): Schema |
| 28 | + { |
| 29 | + return $schema |
| 30 | + ->components([ |
| 31 | + \Filament\Forms\Components\TextInput::make('name') |
| 32 | + ->required() |
| 33 | + ->maxLength(255), |
| 34 | + \Filament\Forms\Components\Select::make('type') |
| 35 | + ->options([ |
| 36 | + 'folder' => 'Folder', |
| 37 | + 'file' => 'File', |
| 38 | + ]) |
| 39 | + ->required(), |
| 40 | + \Filament\Forms\Components\Select::make('parent_id') |
| 41 | + ->relationship('parent', 'name') |
| 42 | + ->searchable() |
| 43 | + ->preload(), |
| 44 | + ]); |
| 45 | + } |
| 46 | + |
| 47 | + public static function table(Table $table): Table |
| 48 | + { |
| 49 | + return $table |
| 50 | + ->columns([ |
| 51 | + Tables\Columns\TextColumn::make('name') |
| 52 | + ->searchable() |
| 53 | + ->sortable(), |
| 54 | + Tables\Columns\TextColumn::make('type') |
| 55 | + ->badge() |
| 56 | + ->color(fn (string $state): string => match ($state) { |
| 57 | + 'folder' => 'success', |
| 58 | + 'file' => 'info', |
| 59 | + }), |
| 60 | + Tables\Columns\TextColumn::make('parent.name') |
| 61 | + ->label('Parent Folder') |
| 62 | + ->searchable() |
| 63 | + ->sortable(), |
| 64 | + Tables\Columns\TextColumn::make('creator.name') |
| 65 | + ->label('Created By') |
| 66 | + ->searchable() |
| 67 | + ->sortable(), |
| 68 | + Tables\Columns\TextColumn::make('created_at') |
| 69 | + ->dateTime() |
| 70 | + ->sortable() |
| 71 | + ->toggleable(isToggledHiddenByDefault: true), |
| 72 | + Tables\Columns\TextColumn::make('updated_at') |
| 73 | + ->dateTime() |
| 74 | + ->sortable() |
| 75 | + ->toggleable(isToggledHiddenByDefault: true), |
| 76 | + ]) |
| 77 | + ->filters([ |
| 78 | + Tables\Filters\SelectFilter::make('type') |
| 79 | + ->options([ |
| 80 | + 'folder' => 'Folder', |
| 81 | + 'file' => 'File', |
| 82 | + ]), |
| 83 | + ]) |
| 84 | + ->actions([ |
| 85 | + Tables\Actions\EditAction::make(), |
| 86 | + Tables\Actions\DeleteAction::make(), |
| 87 | + ]) |
| 88 | + ->bulkActions([ |
| 89 | + Tables\Actions\BulkActionGroup::make([ |
| 90 | + Tables\Actions\DeleteBulkAction::make(), |
| 91 | + ]), |
| 92 | + ]); |
| 93 | + } |
| 94 | + |
| 95 | + public static function getRelations(): array |
| 96 | + { |
| 97 | + return [ |
| 98 | + // |
| 99 | + ]; |
| 100 | + } |
| 101 | + |
| 102 | + public static function getPages(): array |
| 103 | + { |
| 104 | + return [ |
| 105 | + 'index' => Pages\ListLibraryItems::route('/'), |
| 106 | + 'create' => Pages\CreateLibraryItem::route('/create'), |
| 107 | + 'edit' => Pages\EditLibraryItem::route('/{record}/edit'), |
| 108 | + ]; |
| 109 | + } |
| 110 | +} |
0 commit comments