forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserResource.php
More file actions
116 lines (105 loc) · 4.06 KB
/
UserResource.php
File metadata and controls
116 lines (105 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\UserResource\Pages\EditUser;
use App\Models\User;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\HtmlString;
use Illuminate\Validation\Rules\Password;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static ?string $navigationGroup = 'System';
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?int $navigationSort = 0;
protected static ?string $slug = 'system/users';
public static function form(Form $form): Form
{
return $form
->schema([
'left' => Card::make([
'name' => TextInput::make('name')
->required(),
'email' => TextInput::make('email')
->required()
->email()
->unique(ignoreRecord: true),
'password' => TextInput::make('password')
->required()
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->visible(fn ($livewire) => $livewire instanceof CreateUser)
->rule(Password::default()),
'new_password_group' => Group::make([
'new_password' => TextInput::make('new_password')
->password()
->label('New Password')
->nullable()
->rule(Password::default())
->visible(fn ($livewire) => $livewire instanceof EditUser)
->dehydrated(false),
'new_password_confirmation' => TextInput::make('new_password_confirmation')
->password()
->label('Confirm New Password')
->rule('required', fn ($get) => (bool) $get('new_password'))
->same('new_password')
->visible(fn ($livewire) => $livewire instanceof EditUser)
->dehydrated(false),
]),
])->columnSpan(8),
'right' => Card::make([
'created_at' => Placeholder::make('created_at')
->content(fn ($record) => $record?->created_at?->diffForHumans() ?? new HtmlString('—')),
])->columnSpan(4),
])
->columns(12);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
TextColumn::make('email'),
TextColumn::make('email_verified_at')
->dateTime(),
TextColumn::make('created_at')
->dateTime(),
TextColumn::make('updated_at')
->dateTime(),
])
->filters([
//
])
->actions([
EditAction::make(),
])
->bulkActions([
DeleteBulkAction::make(),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}