Hi everyone,
I’m working with Filament 4 and Laravel 12. I have a user model with a canAccessPanel() method to control access to my admin panel:
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return str_ends_with($this->email, '@example.com') && $this->hasVerifiedEmail();
}
return true;
}
Currently, if a user who is not allowed tries to access the admin panel, Filament shows a 403 error page. I want to redirect them to the homepage (/) instead.
I’ve tried returning redirect('/') directly in canAccessPanel(), but that breaks the type contract and throws errors. I also tried modifying the exception handler, but nothing works reliably with Livewire requests.
My questions:
What’s the recommended way in Laravel 12 + Filament 4 to redirect unauthorized users from the admin panel to the homepage?
How can this work with both normal requests and Livewire/AJAX requests inside Filament?
Is using a middleware the best approach, or is there a simpler way?
Thanks in advance for any guidance or example snippets!