Laravel 5 注销或会话销毁

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34292261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:49:16  来源:igfitidea点击:

Laravel 5 logout or session destroy

phplaravel

提问by Iannazzi

I am having issues logging out of a laravel 5.1 app - I believe the issue is that the session is not destroyed.

我在注销 laravel 5.1 应用程序时遇到问题 - 我认为问题在于会话没有被破坏。

My question is nearly identical to:

我的问题几乎与以下相同:

Laravel 5 Auth Logout not destroying session

Laravel 5 Auth 注销不会破坏会话

with the caveat that my solution is to use

需要注意的是,我的解决方案是使用

session_unset();

rather than

而不是

Session::flush();

so my working solution to logging out of a laravel 5.1 app is:

所以我注销 laravel 5.1 应用程序的工作解决方案是:

public function getLogout()
{
    \Auth::logout();
    session_unset();
    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');

    //these attempts will not remove values from the session.....

    //session()->forget('db');
    //\Session::flush();


}

any ideas why \Session::flush();and session()->forget('db');are not working?

任何想法为什么\Session::flush();session()->forget('db');不起作用?

回答by Ali Erdem Sunar

Could you try this:

你可以试试这个:

Auth::logout();
Session::flush();

If It's not working, check "'driver' => 'file'"or "'domain' => null"sections in Config->Session.php.

如果它不起作用,请检查Config->Session.php 中的"'driver' => 'file'""'domain' => null"部分。

回答by Kamani Anand

Try This Code

试试这个代码

Auth::logout();

or

或者

session_unset();

or

或者

Session::flush();

回答by Vishal Vaghasiya

Try this code

试试这个代码

use Illuminate\Support\Facades\Session;

使用 Illuminate\Support\Facades\Session;

public function logout()
{
    Auth::logout();
    Session::flush();
    return redirect('/login');
 }