Configuring canAccessPanel
I am using filament 3 and the new multi panel feature. I have 2 panels, one for admin and another for user. In the User.php model, i have the following:
public function canAccessPanel(Panel $panel): bool
{
return $this->is_admin;
}
This works - admins can view both the admin panel and user panel. However, a normal user cannot access the user panel due to this. How do I fix this?
15 Replies
Hi,
What's not working about that?
it's working,
Sounded like a question not an answer. Can you maybe edit your answer and add code formatting ( #✅┊rules ). Then I can mark this as the answers.
Sure.
I think you used a signle backtick. Can you try with triple backticks again? 🙈
When I enter the wrong credentials it gives me a 403 forbidden error page. Can I show the user some kind of message or notification rather than an error screen? 🤔
is there any way to customize this error screen?
Rather than a error screen can i show a notification to the user? Like "You do not have permission to login to this panel" ? 🤔
is there any way to achive that kind of thing? @Hasnayeen
you've to use custom login page https://filamentphp.test/docs/3.x/panels/users#customizing-the-authentication-features
just copy filament login page and customize this section
Now i set up the custom login page. How can i set up a validation message or notification? if $email != "some email" ?
I have 2 panels too, User and Admin...
I created 2 differents resources to the same model (User).
Have you already had the problem that canAccessPanel is called just from Admin Panel ?
If i put dd() inside de function, and access from both panels, just admin show the debug.
rsrsrs...
Created a new panel to compare, and I realized that I had removed for error \the "use Filament\Http\Middleware\Authenticate" from middleware. Sorry