Created
March 31, 2023 19:39
-
-
Save NandoKstroNet/2ba9e9234f162142074f60aacddcda7a to your computer and use it in GitHub Desktop.
Category Resource - FilamentPHP do curso FilamentPHP na Prática em https://codeexperts.com.br
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Filament\Resources; | |
| use App\Filament\Resources\CategoryResource\Pages; | |
| use App\Filament\Resources\CategoryResource\RelationManagers; | |
| use App\Models\Category; | |
| use Filament\Tables\Columns\TextColumn; | |
| use Filament\Forms\Components\TextInput; | |
| use Filament\Resources\Form; | |
| use Filament\Resources\Resource; | |
| use Filament\Resources\Table; | |
| use Filament\Tables; | |
| use Illuminate\Database\Eloquent\Builder; | |
| use Illuminate\Database\Eloquent\SoftDeletingScope; | |
| use Illuminate\Support\Str; | |
| class CategoryResource extends Resource | |
| { | |
| protected static ?string $model = Category::class; | |
| protected static ?string $navigationIcon = 'heroicon-o-collection'; | |
| public static function form(Form $form): Form | |
| { | |
| return $form | |
| ->schema([ | |
| TextInput::make('name') | |
| ->reactive() | |
| ->afterStateUpdated(function ($state, $set) { | |
| $state = Str::slug($state); | |
| $set('slug', $state); | |
| }) | |
| ->label('Nome Categoria'), | |
| TextInput::make('slug')->disabled(), | |
| ]); | |
| } | |
| public static function table(Table $table): Table | |
| { | |
| return $table | |
| ->columns([ | |
| TextColumn::make('id')->sortable(), | |
| TextColumn::make('name')->sortable()->searchable(), | |
| ]) | |
| ->filters([ | |
| // | |
| ]) | |
| ->actions([ | |
| Tables\Actions\EditAction::make(), | |
| ]) | |
| ->bulkActions([ | |
| Tables\Actions\DeleteBulkAction::make(), | |
| ]); | |
| } | |
| public static function getRelations(): array | |
| { | |
| return [ | |
| // | |
| ]; | |
| } | |
| public static function getPages(): array | |
| { | |
| return [ | |
| 'index' => Pages\ListCategories::route('/'), | |
| 'create' => Pages\CreateCategory::route('/create'), | |
| 'edit' => Pages\EditCategory::route('/{record}/edit'), | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment