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

PRESTIGE2930's avatar

How to change redirect route in laravel 11.

in my web.app file, i have something like this

Route::middleware(['auth'], function(){ // Some route })

but i want to specify what route to redirect to if the auth fails.

In the previous versions of laravel, i usually go into the auth middleware andspecify the redirect route, but with this new laravel 11, I am a bit confused on where or what to do.

since "Illuminate\Auth\Middleware" and "Illuminate\Auth" are now path of the framework and cannot be changed

1 like
3 replies
amitsolanki24_'s avatar
Level 8

You can change from bootstrap app.php file

Here is the reference link:

https://laravel.com/docs/11.x/authentication#redirecting-unauthenticated-users
->withMiddleware(function (Middleware $middleware) {
    $middleware->redirectGuestsTo('/login');
 
    // Using a closure...
    $middleware->redirectGuestsTo(fn (Request $request) => route('login'));
})
3 likes

Please or to participate in this conversation.