简体   繁体   English

Laravel Auth :: logout()无法正常工作

[英]Laravel Auth::logout() not working properly

I am trying to log out a user but it doesn't seem to be working... 我正在尝试注销用户,但似乎不起作用...

public function logout() {

        $user = Auth::user();
        Auth::logout($user);

        return Redirect::to('/');
    }

If I comment out the first two lines, the redirect works... But the logout part just doesn't. 如果我注释掉前两行,则重定向有效……但是注销部分却没有。

Try to use Auth::logout(); 尝试使用Auth :: logout(); - without any parameters. -没有任何参数。

You might encounter an error saying that there is no remember_token field in your table, to fix this, find: PROJECT_FOLDER/vendor/laravel/framework/src/Illuminate/Auth/Guard.php , then comment out line 520 . 您可能会遇到一个错误,指出存在的表中没有remember_token领域,要解决这个问题,发现:PROJECT_FOLDER /供应商/ laravel /框架/ src目录/照亮/认证/ Guard.php,然后注释掉线520。

Or you can fix this by adding a column 'remember_token' in your user table. 或者,您可以通过在用户表中添加“ remember_token”列来解决此问题。

Ultimately, yes - 最终,是的-

Under the hood, the only thing that really needs to happen is session_destroy() - 真正需要做的唯一事情就是session_destroy() -

As far as Laravel is concerned, this function exists in case there is any other clean up that needs to be done... for example, if a 'remember me' cookie needs to be deactivated... 就Laravel而言,此功能存在以防万一需要进行其他清理...例如,如果需要停用``记住我''cookie ...

But, to test your Laravel script, you could have a page - let's call it sessionTest.php - 但是,要测试您的Laravel脚本,您可以创建一个页面-我们将其称为sessionTest.php

<?php

echo "<pre>"; 
print_r($_SESSION); 


?> 

If you visit this page before and after your logout - then you should have a better idea of what is going on. 如果您在注销之前和之后访问此页面-那么您应该对发生的事情有更好的了解。

If Laravel is really failing, it could be a Remember_me cookie that isn't being cleaned up properly, or some other strange issue that we would need to investigate further... 如果Laravel确实失败了,则可能是没有正确清理的Remember_me cookie,或者我们需要进一步调查的其他奇怪问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM