by default it should redirect, but you have changed something
Feb 5, 2025
2
Level 1
Laravel 11 guest re-direct not working
I'm working on a Laravel 11 project using the Spatie Roles & Permissions package for user roles and permissions.
When a guest user tries to access a route which is for authenticated users the expected re-direct to the login page does not occur instead the '403 USER IS NOT LOGGED IN' page is shown instead. Is the re-direct not automatically done with L11?
I tried adding :-
$middleware->redirectGuestsTo( fn( Request $request ) => route( 'login' ) );
to the config/app.php withMiddleware() section but it had no effect.
Is there something I have missed?
TIA!
Please or to participate in this conversation.