Laravel 5.2: Auth::logout() is not working

Felipe Peña picture Felipe Peña · Dec 27, 2015 · Viewed 27.8k times · Source

I'm building a very simple app in Laravel 5.2, but when using AuthController's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check() and it doesn't change after calling the log out action.

I have this route inside the routes.php file:

Route::get('users/logout', 'Auth\AuthController@getLogout');

and it's outside the

Route::group(['middleware' => ['web']], function () statement.

I did also try to add the follow action at the end of the AuthController.php file.

public function getLogout() 
{
    $this->auth->logout();
    Session::flush();
    return redirect('/');
}

Do you have any ideas?

EDIT 1

If I clear Google's Chrome cache, it works.

Answer

Aztecnologic picture Aztecnologic · Jan 8, 2016

I also had similar problem in Laravel 5.2. You should change your route to

Route::get('auth/logout', 'Auth\AuthController@logout');

or in AuthController constructor add

public function __construct()
{
    $this->middleware('guest', ['except' => ['logout', 'getLogout']]);
}

That worked for me.