admin: User implements FilamentUser (canAccessPanel=isAdmin) — fixes 403 in production
This commit is contained in:
@@ -2,29 +2,39 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Filament\Models\Contracts\FilamentUser;
|
||||||
|
use Filament\Panel;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable implements FilamentUser
|
||||||
{
|
{
|
||||||
use HasFactory, Notifiable;
|
use HasFactory, Notifiable;
|
||||||
|
|
||||||
protected $table = "users";
|
protected $table = 'users';
|
||||||
public $timestamps = false; // shared schema: created_at only, set by DB default
|
public $timestamps = false; // shared schema: created_at only, set by DB default
|
||||||
protected $fillable = ["email", "password_hash", "name", "phone", "is_admin"];
|
protected $fillable = ['email', 'password_hash', 'name', 'phone', 'is_admin'];
|
||||||
protected $hidden = ["password_hash"];
|
protected $hidden = ['password_hash'];
|
||||||
protected $casts = ["is_admin" => "boolean"];
|
protected $casts = ['is_admin' => 'boolean'];
|
||||||
|
|
||||||
public function getAuthPassword(): string
|
public function getAuthPassword(): string
|
||||||
{
|
{
|
||||||
return $this->password_hash;
|
return $this->password_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filament panel access — only admins may use the admin panel.
|
||||||
|
*/
|
||||||
|
public function canAccessPanel(Panel $panel): bool
|
||||||
|
{
|
||||||
|
return $this->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
public function tags(): HasMany
|
public function tags(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Tag::class, "owner_id");
|
return $this->hasMany(Tag::class, 'owner_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isAdmin(): bool
|
public function isAdmin(): bool
|
||||||
|
|||||||
Reference in New Issue
Block a user