|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\Resources; |
| 4 | + |
| 5 | +use App\Filament\Resources\UserResource\Pages; |
| 6 | +use App\Models\User; |
| 7 | +use Filament\Forms; |
| 8 | +use Filament\Forms\Form; |
| 9 | +use Filament\Resources\Resource; |
| 10 | +use Filament\Tables; |
| 11 | +use Filament\Tables\Table; |
| 12 | + |
| 13 | +class UserResource extends Resource |
| 14 | +{ |
| 15 | + protected static ?string $model = User::class; |
| 16 | + |
| 17 | + protected static ?string $navigationIcon = 'heroicon-o-users'; |
| 18 | + |
| 19 | + public static function form(Form $form): Form |
| 20 | + { |
| 21 | + return $form |
| 22 | + ->schema([ |
| 23 | + Forms\Components\TextInput::make('first_name') |
| 24 | + ->autofocus() |
| 25 | + ->required() |
| 26 | + ->maxLength(255), |
| 27 | + |
| 28 | + Forms\Components\TextInput::make('last_name') |
| 29 | + ->required() |
| 30 | + ->maxLength(255), |
| 31 | + |
| 32 | + Forms\Components\TextInput::make('email') |
| 33 | + ->required() |
| 34 | + ->email() |
| 35 | + ->maxLength(255), |
| 36 | + |
| 37 | + Forms\Components\TextInput::make('password') |
| 38 | + ->password() |
| 39 | + ->maxLength(255), |
| 40 | + |
| 41 | + Forms\Components\DateTimePicker::make('email_verified_at'), |
| 42 | + ]); |
| 43 | + } |
| 44 | + |
| 45 | + public static function table(Table $table): Table |
| 46 | + { |
| 47 | + return $table |
| 48 | + ->columns([ |
| 49 | + Tables\Columns\TextColumn::make('name') |
| 50 | + ->getStateUsing(fn ($record) => $record->fullName) |
| 51 | + ->searchable() |
| 52 | + ->sortable(), |
| 53 | + |
| 54 | + Tables\Columns\TextColumn::make('email') |
| 55 | + ->searchable() |
| 56 | + ->sortable(), |
| 57 | + |
| 58 | + Tables\Columns\IconColumn::make('email_verified') |
| 59 | + ->getStateUsing(fn ($record) => $record->email_verified_at) |
| 60 | + ->boolean() |
| 61 | + ->sortable(), |
| 62 | + |
| 63 | + Tables\Columns\TextColumn::make('roles') |
| 64 | + ->getStateUsing(fn ($record) => $record->roles->pluck('name')->join(', ')) |
| 65 | + ->searchable() |
| 66 | + ->sortable(), |
| 67 | + |
| 68 | + Tables\Columns\TextColumn::make('created_at') |
| 69 | + ->sortable(), |
| 70 | + |
| 71 | + Tables\Columns\TextColumn::make('updated_at') |
| 72 | + ->sortable(), |
| 73 | + ]) |
| 74 | + ->filters([ |
| 75 | + // |
| 76 | + ]) |
| 77 | + ->actions([ |
| 78 | + Tables\Actions\EditAction::make(), |
| 79 | + ]) |
| 80 | + ->bulkActions([ |
| 81 | + Tables\Actions\BulkActionGroup::make([ |
| 82 | + Tables\Actions\DeleteBulkAction::make(), |
| 83 | + ]), |
| 84 | + ]); |
| 85 | + } |
| 86 | + |
| 87 | + public static function getRelations(): array |
| 88 | + { |
| 89 | + return [ |
| 90 | + // |
| 91 | + ]; |
| 92 | + } |
| 93 | + |
| 94 | + public static function getPages(): array |
| 95 | + { |
| 96 | + return [ |
| 97 | + 'index' => Pages\ListUsers::route('/'), |
| 98 | + 'create' => Pages\CreateUser::route('/create'), |
| 99 | + 'edit' => Pages\EditUser::route('/{record}/edit'), |
| 100 | + ]; |
| 101 | + } |
| 102 | +} |
0 commit comments