Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 logout or session destroy

Tags:

php

laravel

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?

like image 866
Iannazzi Avatar asked Dec 15 '15 14:12

Iannazzi


2 Answers

Could you try this:

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

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

like image 52
Ali Erdem Sunar Avatar answered Sep 20 '22 12:09

Ali Erdem Sunar


Try This Code

Auth::logout();

or

session_unset();

or

Session::flush();
like image 41
Kamani Anand Avatar answered Sep 22 '22 12:09

Kamani Anand