forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserForm.php
More file actions
86 lines (77 loc) · 3.24 KB
/
UserForm.php
File metadata and controls
86 lines (77 loc) · 3.24 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
<?php
namespace App\Filament\Resources\Users\Schemas;
use App\Enums\UserRole;
use App\Models\User;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class UserForm
{
public static function schema(): array
{
return [
Grid::make([
'default' => 1,
])->columnSpan([
'lg' => 2,
])->schema([
Section::make(__('general.details'))
->columns([
'default' => 1,
'lg' => 2,
])
->schema([
TextInput::make('name')
->label(__('general.name'))
->required()
->maxLength(255)
->columnSpanFull(),
TextInput::make('email')
->label(__('general.email'))
->email()
->required()
->maxLength(255)
->columnSpanFull(),
TextInput::make('password')
->label(__('general.password'))
->confirmed()
->password()
->revealable()
->required(fn (string $context): bool => $context === 'create')
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state)),
TextInput::make('password_confirmation')
->label(__('general.password_confirmation'))
->password()
->revealable(),
]),
]),
Grid::make(1)
->columnSpan(1)
->schema([
Section::make(__('general.platform'))
->schema([
Select::make('role')
->label(__('general.role'))
->default(UserRole::User)
->options(UserRole::class)
->required()
->disabled(fn (?User $record): bool => Auth::user()->role !== UserRole::Admin),
]),
Section::make()
->schema([
Placeholder::make('created_at')
->label(__('general.created_at'))
->content(fn (?User $record): string => $record ? $record->created_at->diffForHumans() : '-'),
Placeholder::make('updated_at')
->label(__('general.updated_at'))
->content(fn (?User $record): string => $record ? $record->updated_at->diffForHumans() : '-'),
]),
]),
];
}
}