I\'m working with Laravel 5 authentification system provided by default. After logging out, a user is redirected to the root page but I\'d like to change that. I managed to
it'only laravel versi 5.4 if you want custom redirect url logout,
open /your-project-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
and edit redirect based on you needed
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/login');
}
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.
In App\Controllers\Auth\AuthController, add the following two variables.
protected $redirectTo = '/private_dashboard';
protected $redirectAfterLogout = '/public_homepage';
You get the idea.
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');
}
For Laravel 5.5 override logout method inside LoginController. In my case I am redirecting to home route after login.
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect()->route('home');
}
using the built in laravel Auth in the controllers I just override the loggedOut method which triggers after logout to redirect
in the "LoginController.php" which uses
use AuthenticatesUsers;
in the AuthenticatesUsers Trait is a logout method, you can optionally override this or you will see that it triggers a loggedOut method
You can override the logged out method which is default blank and have that redirect
/**
* The user has logged out of the application.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
protected function loggedOut()
{
return redirect()->route('login.show');
}