|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\Admin\Resources; |
| 4 | + |
| 5 | +use App\Filament\Admin\Resources\UserResource\Pages; |
| 6 | +use App\Filament\Admin\Resources\UserResource\RelationManagers; |
| 7 | +use App\Models\User; |
| 8 | +use Filament\Forms; |
| 9 | +use Filament\Forms\Form; |
| 10 | +use Filament\Resources\Resource; |
| 11 | +use Filament\Tables; |
| 12 | +use Filament\Tables\Table; |
| 13 | +use Illuminate\Database\Eloquent\Builder; |
| 14 | +use Illuminate\Database\Eloquent\SoftDeletingScope; |
| 15 | + |
| 16 | +class UserResource extends Resource |
| 17 | +{ |
| 18 | + protected static ?string $model = User::class; |
| 19 | + |
| 20 | + protected static ?string $navigationIcon = 'heroicon-o-users'; |
| 21 | + |
| 22 | + protected static ?string $navigationGroup = "User Management"; |
| 23 | + |
| 24 | + public static function form(Form $form): Form |
| 25 | + { |
| 26 | + return $form |
| 27 | + ->schema([ |
| 28 | + Forms\Components\Section::make() |
| 29 | + ->columns(2) |
| 30 | + ->schema([ |
| 31 | + Forms\Components\TextInput::make('name') |
| 32 | + ->required() |
| 33 | + ->maxLength(191), |
| 34 | + Forms\Components\Select::make('roles') |
| 35 | + ->label(__('Role')) |
| 36 | + ->relationship('roles', 'name') |
| 37 | + ->preload() |
| 38 | + ->native(false) |
| 39 | + ->required(), |
| 40 | + Forms\Components\TextInput::make('email') |
| 41 | + ->email() |
| 42 | + ->required() |
| 43 | + ->maxLength(191), |
| 44 | + Forms\Components\TextInput::make('password') |
| 45 | + ->password() |
| 46 | + ->maxLength(191), |
| 47 | + |
| 48 | + Forms\Components\FileUpload::make('profile_photo_path') |
| 49 | + ->image() |
| 50 | + ->label("Image"), |
| 51 | + ]) |
| 52 | + ]); |
| 53 | + } |
| 54 | + |
| 55 | + public static function table(Table $table): Table |
| 56 | + { |
| 57 | + return $table |
| 58 | + ->columns([ |
| 59 | + Tables\Columns\ImageColumn::make('profile_photo_path') |
| 60 | + ->label(""), |
| 61 | + Tables\Columns\TextColumn::make('name') |
| 62 | + ->searchable(), |
| 63 | + Tables\Columns\TextColumn::make('email') |
| 64 | + ->searchable(), |
| 65 | + Tables\Columns\TextColumn::make('email_verified_at') |
| 66 | + ->dateTime() |
| 67 | + ->sortable() |
| 68 | + ->toggleable(isToggledHiddenByDefault: true), |
| 69 | + Tables\Columns\TextColumn::make('created_at') |
| 70 | + ->dateTime() |
| 71 | + ->sortable() |
| 72 | + ->toggleable(isToggledHiddenByDefault: true), |
| 73 | + Tables\Columns\TextColumn::make('updated_at') |
| 74 | + ->dateTime() |
| 75 | + ->sortable() |
| 76 | + ->toggleable(isToggledHiddenByDefault: true), |
| 77 | + ]) |
| 78 | + ->filters([ |
| 79 | + // |
| 80 | + ]) |
| 81 | + ->actions([ |
| 82 | + Tables\Actions\EditAction::make(), |
| 83 | + Tables\Actions\DeleteAction::make(), |
| 84 | + ]) |
| 85 | + ->bulkActions([ |
| 86 | + Tables\Actions\BulkActionGroup::make([ |
| 87 | + Tables\Actions\DeleteBulkAction::make(), |
| 88 | + ]), |
| 89 | + ]); |
| 90 | + } |
| 91 | + |
| 92 | + public static function getRelations(): array |
| 93 | + { |
| 94 | + return [ |
| 95 | + // |
| 96 | + ]; |
| 97 | + } |
| 98 | + |
| 99 | + public static function getPages(): array |
| 100 | + { |
| 101 | + return [ |
| 102 | + 'index' => Pages\ListUsers::route('/'), |
| 103 | + 'create' => Pages\CreateUser::route('/create'), |
| 104 | + 'edit' => Pages\EditUser::route('/{record}/edit'), |
| 105 | + ]; |
| 106 | + } |
| 107 | +} |
0 commit comments