diff --git a/app/Models/User.php b/app/Models/User.php index 5fb63b8..2f2214c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,8 @@ namespace App\Models; +use Filament\Models\Contracts\FilamentUser; +use Filament\Panel; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -10,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Support\Facades\Hash; use Spatie\Permission\Traits\HasRoles; -class User extends Authenticatable +class User extends Authenticatable implements FilamentUser { use HasApiTokens, HasFactory, Notifiable, HasRoles; @@ -45,6 +47,11 @@ class User extends Authenticatable 'password' => 'hashed', // Laravel 10+ soporta casting a hashed ]; + public function canAccessPanel(Panel $panel): bool + { + return $this->hasAnyRole(['Administrador', 'Super Admin']) || $this->hasPermissionTo('view_admin'); + } + /** * Get the roles associated with the user. */ @@ -53,5 +60,5 @@ class User extends Authenticatable return $this->belongsToMany(Role::class); } - + }