How to change the redirect url when logging out?

For Laravel 5,

Open AuthController class : app/Http/Controllers/Auth/AuthController.php

Add below property to the class

protected $redirectAfterLogout = 'auth/login';

you can change auth/login with any url.


If you don't provide the $redirectAfterLogout attribute, it will use the default which is '/'.

This logic can be found in this class: \vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

public function logout()
{
    Auth::guard($this->getGuard())->logout();

    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}

Having said that, just add this attribute in your AuthController:

protected $redirectAfterLogout = '/afterRedirectURL';

The redirect after logout is hard coded in the trait AuthenticatesAndRegistersUsers. You can override it in your AuthController by adding this:

public function getLogout()
{
    $this->auth->logout();

    return redirect('logout');
}