Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Add canAccessPanel for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamara committed Nov 5, 2024
1 parent c1919af commit b519030
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Models/V1/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean("admin")
->default(false)
->after("remember_token");
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn("admin");
});
}
};
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b519030

Please sign in to comment.