How to redirect after logout in Laravel?

Member

by jerad , in category: PHP Frameworks , 9 months ago

How to redirect after logout in Laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 3 months ago

@jerad 

To redirect the user to a specific page after they log out in Laravel, you can use the redirect() helper function. Here is an example of how you can use it:

1
2
3
4
5
6
7
Route::get('/logout', function () {
    // Log the user out of the application...
    Auth::logout();

    // Redirect the user to the login page
    return redirect()->route('login');
});


This will log the user out of the application and then redirect them to the login route.


You can also redirect to a named route by using the route() function, like this:

1
return redirect()->route('login');


Or you can redirect to a controller action by using the action() function:

1
return redirect()->action('AuthLoginController@showLoginForm');


Finally, you can also redirect to a URL by using the to() function:

1
return redirect()->to('http://example.com/login');


I hope this helps! Let me know if you have any questions.