Laravel 5.2:Auth :: logout()无法正常工作 [英] Laravel 5.2: Auth::logout() is not working
问题描述
我正在Laravel 5.2中构建一个非常简单的应用程序,但是当使用AuthController
的操作注销时,它根本无法工作.我有一个导航栏,它会检查Auth::check()
,并且在调用注销操作后不会更改.
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.
我在routes.php文件中有此路由:
I have this route inside the routes.php file:
Route::get('users/logout', 'Auth\AuthController@getLogout');
它在
Route::group(['middleware' => ['web']], function ()
语句.
我也确实尝试在AuthController.php文件的末尾添加跟随动作.
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('/');
}
你有什么主意吗?
编辑1
如果我清除了Google的Chrome缓存,它将起作用.
If I clear Google's Chrome cache, it works.
推荐答案
在Laravel 5.2中,我也遇到了类似的问题.您应该将路线更改为
I also had similar problem in Laravel 5.2. You should change your route to
Route::get('auth/logout', 'Auth\AuthController@logout');
或在AuthController构造函数中添加
or in AuthController constructor add
public function __construct()
{
$this->middleware('guest', ['except' => ['logout', 'getLogout']]);
}
对我有用.
这篇关于Laravel 5.2:Auth :: logout()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!