Laravel 5.2 Auth退出失效问题描述
用户反馈登录功能运行正常,但在尝试退出时,Session数据并未被清除,导致系统依然认为用户处于已登录状态。针对这一现象,具体的修复方案如下:
首先检查路由配置文件,确保相关路径定义无误。
Route::group(['namespace' => 'Admin', 'middleware' => 'auth'], function() {
Route::resource('admin/post', 'PostController');
});
// 登陆
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
// 5.2版本这里的方法需要写成logout,因为在中间件中是这么定义的
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
// 路由中的方法要跟上述一致
Route::get('auth/logout', 'Auth\AuthController@logout');
接着查看AuthController.php控制器中的逻辑实现。
// 登录成功后跳转地址
protected $redirectTo = 'admin/post';
// 退出后跳转地址
protected $redirectAfterLogout = 'auth/login';
该问题的具体成因及解法可参考StackOverflow上的讨论:http://stackoverflow.com/questions/34479994/laravel-5-2-authlogout-is-not-working
在调试过程中,若在AppServiceProvider的boot方法中添加SQL监听输出代码,也可能引发类似的错误。因此,在进行登录相关的调试时,建议避免此类操作。
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// \DB::listen(function($sql) {
// dump($sql->sql);
// });
}
上述内容即为解决Laravel 5.2 Auth认证退出失效问题的完整方案,希望能为您提供有效参考。欢迎收藏本站以获取更多技术支持。