Redirect to specified route after logout – Laravel

May 10, 2020

Redirect after logout

In default Laravel app, once you logout it will redirect to the home page.

But you can change where to redirect after you log out.
Never edit the core files located at your vendor folder that will override when you update the Laravel versions

In Auth\LoginController you have the following trait

use AuthenticatesUsers;

You can change it with following

use AuthenticatesUsers {
     logout as performLogout;
}

Now you can define the logout function which will override the logout @ AuthenticatesUsers trait

public function logout(Request $request)
{
    $this->performLogout($request);
    return redirect()->route(‘login’);
}

Basically we are calling the logout@AuthenticatesUsers trait by passing the $request and finally redirect where we want after logging out