How to set laravel 5.3 logout redirect path? How to set laravel 5.3 logout redirect path? laravel laravel

How to set laravel 5.3 logout redirect path?


This is how I did it. In Auth\LoginController you have:

use AuthenticatesUsers;

Change it to:

use AuthenticatesUsers {    logout as performLogout;}

Then, define a new logout() method in your LoginController:

public function logout(Request $request){    $this->performLogout($request);    return redirect()->route('your_route');}

Sure, regular logout() method in that trait has only 3 lines (used to log users out of the system) so you can copy them to your method, but you should always follow the DRY principle (don't repeat yourself) and re-use as much code as you can.


Laravel > 5.7

The accepted answer is fine, but you can completely bypass touching any of the logout logic by simply overwriting the loggedOut method:

// App\Http\Controllers\Auth\LoginController.phpprotected function loggedOut(Request $request) {    return redirect('/where/ever/you/want/to/go');}


I would inherit LoginController and override the logout function coming from the trait in there:

LoginController.php -> leave that as it is.

MyLoginController.php:

class MyLoginController extends LoginController {protected $redirectAfterLogout = '/goodbye';    public function logout(Request $request)    {        $this->guard()->logout();        $request->session()->flush();        $request->session()->regenerate();        return redirect($this->redirectAfterLogout);    }}

Of course, you should remember to update your Auth routes accordingly.