fix: implement FilamentUser interface on User model to allow panel access in production

This commit is contained in:
Lizandro Guarnizo
2026-06-09 17:45:26 -05:00
parent 095307a456
commit b6feb44470
+9 -2
View File
@@ -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);
}
}