fix: implement FilamentUser interface on User model to allow panel access in production
This commit is contained in:
+9
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user