Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rich06's avatar
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!

0 likes
2 replies
Snapey's avatar

by default it should redirect, but you have changed something

1 like
rich06's avatar
Level 1

@Snapey - thanks for the quick response :) After I posted my message I looked at this a bit more and the route was being 'protected' by a user role but not 'auth' - so once I changed that it started working.

Sorry for the noise!

Please or to participate in this conversation.