F
Filament3mo ago
Mahdi

filament-shield: How to prevent a user from accessing the panel when he has no permissions?

this is work just in case the name of role is the same with panel name
public function canAccessPanel(Panel $panel): bool
{
$userRole = $this->roles()->first()->name;
$currentPanel = filament()->getCurrentPanel()->getId();
if ($currentPanel === $userRole)) {
return true;
}
return false;
}
public function canAccessPanel(Panel $panel): bool
{
$userRole = $this->roles()->first()->name;
$currentPanel = filament()->getCurrentPanel()->getId();
if ($currentPanel === $userRole)) {
return true;
}
return false;
}
1 Reply
Majid Al Zariey
Majid Al Zariey3mo ago
Do you mean
if($this->roles()->count() > 0){
return true;
}

return false
if($this->roles()->count() > 0){
return true;
}

return false