Best Practice for Multi-Panel Auth and Redirects

What is the best practice for: - permissioning access to separate panels - redirecting to a specific panel on login based on roles I am using Filament Shield (with Spatie Roles and Permissions) I have the following panels: - Admin (default) - Teachers - Students - HR Admin should be accessibe by roles: 'Admin' and 'super_admin', Teachers by 'Teachers', Students by 'Students' and HR by 'Human Resources' I adapted the User Model as follows which worked Locally but in production I couldn't access any Panels even as super_admin:
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Admin']);
} else if ($panel->getId() === 'hr') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Human Resources']);
} else if ($panel->getId() === 'teachers') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Teacher']);
} else if ($panel->getId() === 'students') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Student']);
}
return false;
}
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Admin']);
} else if ($panel->getId() === 'hr') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Human Resources']);
} else if ($panel->getId() === 'teachers') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Teacher']);
} else if ($panel->getId() === 'students') {
return $this->email && $this->hasVerifiedEmail() && $this->hasRole(['Student']);
}
return false;
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server