Skip to content

Commit 7707036

Browse files
user timezone
1 parent 3fadec9 commit 7707036

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

app/Filament/Resources/UserResource.php

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Filament\Resources\UserResource\Pages;
66
use App\Models\User;
7+
use DateTimeZone;
78
use Filament\Forms;
89
use Filament\Forms\Form;
910
use Filament\Resources\Resource;
@@ -32,6 +33,11 @@ public static function form(Form $form): Form
3233
->disk('public')
3334
->directory('avatars')
3435
->avatar(),
36+
Forms\Components\Select::make('timezone')
37+
->options(
38+
array_combine(DateTimeZone::listIdentifiers(), DateTimeZone::listIdentifiers())
39+
)
40+
->searchable(),
3541
Forms\Components\DateTimePicker::make('email_verified_at'),
3642
Forms\Components\TextInput::make('password')
3743
->password()
@@ -65,6 +71,7 @@ public static function table(Table $table): Table
6571
->sortable()
6672
->toggleable(isToggledHiddenByDefault: true),
6773
])
74+
->defaultSort('id', 'desc')
6875
->filters([
6976
//
7077
])

app/Models/User.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
* @property string $email
1818
* @property string|null $avatar
1919
* @property \Illuminate\Support\Carbon|null $email_verified_at
20-
* @property mixed $password
20+
* @property string $password
21+
* @property string|null $timezone +7 or Asia/Ho_Chi_Minh
2122
* @property string|null $remember_token
2223
* @property \Illuminate\Support\Carbon|null $created_at
2324
* @property \Illuminate\Support\Carbon|null $updated_at
2425
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
2526
* @property-read int|null $notifications_count
2627
*
2728
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
28-
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
29-
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
30-
* @method static \Illuminate\Database\Eloquent\Builder|User query()
29+
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newModelQuery()
30+
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newQuery()
31+
* @method static \Illuminate\Database\Eloquent\Builder<static>|User query()
3132
*
3233
* @mixin \Illuminate\Database\Eloquent\Model
3334
*/
@@ -50,6 +51,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, MustVerif
5051
'email',
5152
'avatar',
5253
'password',
54+
'timezone',
5355
];
5456

5557
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('users', function (Blueprint $blueprint) {
15+
$blueprint->string('timezone')->nullable()->comment('+7 or Asia/Ho_Chi_Minh')->after('remember_token');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
//
25+
}
26+
};

0 commit comments

Comments
 (0)