Iannazzi
Iannazzi

Reputation: 1388

Laravel 5 logout or session destroy

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

My question is nearly identical to:

Laravel 5 Auth Logout not destroying session

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:

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?

Upvotes: 7

Views: 40717

Answers (3)

Vishal Vaghasiya
Vishal Vaghasiya

Reputation: 2104

Try this code

use Illuminate\Support\Facades\Session;

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

Upvotes: 0

Kamani Anand
Kamani Anand

Reputation: 65

Try This Code

Auth::logout();

or

session_unset();

or

Session::flush();

Upvotes: 2

Ali Erdem Sunar
Ali Erdem Sunar

Reputation: 141

Could you try this:

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

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

Upvotes: 11

Related Questions