From b5190304783ef2fec35df8a4b5972e5224aa0c52 Mon Sep 17 00:00:00 2001 From: kkamara Date: Tue, 5 Nov 2024 00:08:11 +0000 Subject: [PATCH] Add canAccessPanel for admin --- app/Models/V1/User.php | 9 +++++- ...320_alter_users_table_add_admin_column.php | 30 +++++++++++++++++++ database/seeders/DatabaseSeeder.php | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 database/migrations/v1/2024_11_05_000320_alter_users_table_add_admin_column.php diff --git a/app/Models/V1/User.php b/app/Models/V1/User.php index a1540cb..31b1636 100644 --- a/app/Models/V1/User.php +++ b/app/Models/V1/User.php @@ -9,8 +9,10 @@ use Illuminate\Support\Traits\Tappable; use Laravel\Sanctum\HasApiTokens; use Illuminate\Database\Eloquent\Relations\HasMany; +use Filament\Models\Contracts\FilamentUser; +use Filament\Panel; -class User extends Authenticatable +class User extends Authenticatable implements FilamentUser { use HasFactory, Notifiable; use Tappable; @@ -72,4 +74,9 @@ public function orders(): HasMany { public function carts(): HasMany { return $this->hasMany(Cart::class); } + + public function canAccessPanel(Panel $panel): bool + { + return $this->admin == true; + } } diff --git a/database/migrations/v1/2024_11_05_000320_alter_users_table_add_admin_column.php b/database/migrations/v1/2024_11_05_000320_alter_users_table_add_admin_column.php new file mode 100644 index 0000000..44c337e --- /dev/null +++ b/database/migrations/v1/2024_11_05_000320_alter_users_table_add_admin_column.php @@ -0,0 +1,30 @@ +boolean("admin") + ->default(false) + ->after("remember_token"); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn("admin"); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 2fa18af..dfcefbe 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -25,6 +25,7 @@ public function run(): void User::factory()->create([ 'name' => 'Jane Doe', 'email' => 'jane@doe.com', + 'admin' => true, ]); Book::factory()->count(30)->create(); Review::factory()->count(1000)->create();