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();