Starting from Laravel 11, the method of setting the redirection URL for guests changed.
To change the path that guests are redirected to when attempting to access an unauthenticated area, head to bootstrap/app.php
.
You'll need to call the redirectGuestsTo
method within the withMiddleware
callback.
return Application::configure(basePath: dirname(__DIR__))
//...
->withMiddleware(function (Middleware $middleware) {
$middleware->redirectGuestsTo('/auth/login');
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Once you've done that, guests that are attempting to access an area of your application protected by auth
middleware will be redirected here.
And as a side note, while it would be convenient to be able to use the route
helper here to reference a named route, unfortunately this doesn't work, since helpers and Facades are not loaded at this stage of Laravel's lifecycle.