SoFunction
Updated on 2025-04-04

Solve the problem of Laravel5.2 Auth authentication expiration failure

Login is normal, but the session is not cleared when logging out, and it is still in the login state after logging out. The solution is as follows:

The route is as follows

Route::group(['namespace' => 'Admin', 'middleware' => 'auth'], function() {
  Route::resource('admin/post', 'PostController');
});


// Log inRoute::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
// The method here needs to be written as logout in version 5.2, because this is defined in the middlewarepublic function __construct()
 { 
   $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
 }
 // The method in the routing should be consistent with the aboveRoute::get('auth/logout', 'Auth\AuthController@logout');

In-house

// Redirect the address after login successfullyprotected $redirectTo = 'admin/post';
// Redirect the address after exitprotected $redirectAfterLogout = 'auth/login';

refer to/questions/34479994/laravel-5-2-authlogout-is-not-working

Adding output sql to the boot method of AppserveProvider during debugging will also lead to similar errors, so try not to do this when logging in to debugging.

  /**
   * Bootstrap any application services.
   *
   * @return void
   */
  public function boot()
  {
    // \DB::listen(function($sql) {
    //     dump($sql->sql);
    //   });
  }

The above article solves the problem of the invalidation of Laravel5.2 Auth authentication exit is all the content I share with you. I hope you can give you a reference and I hope you can support me more.