samedi 14 janvier 2017

Laravel Session remove/forget with redirect not working

What is wrong with my code here:

 use Illuminate\Support\Facades\Session;
 ...
 public function getFrontlogout(Request $request){
        d(Session::all());
        Session::forget('uid');
        return Redirect::back();
 }    
 public getIndex(Request $request){
    //ddd(Session::all());
    ....
    return view('index',$this->data);
 }

In my index blade I have a button (href) to logout that calls the getFrontlogout function and I want to reload the index AFTER removing some session variables. But the session variables seem to persist after REDIRECT.

So in the getFrontlogout if I do not do the redirect and die-and-dump there the session... it shows that I successfully removed the Session variables. But if I do not die there, and do the redirect, and display the session variables in the getIndex function... looks like nothing was removed from the Session.

I use hard-reload for the pages, and this keeps happening.

What is wrong here? My Session changes get lost when redirecting.

I use Laravel 5.1 and I would like to keep it that way because I have a lot of code that was written for 5.1 and I do not have the time to do an upgrade that would mess up my existing code.

I understand that in 5.2 for some early versions I would have to wrap my routes inside a group(['middleware' => ['web']], function () {...}), and for later 5.2 versions I would not have to do that anymore because they are already wrapped in the middleware.

What about laravel 5.1?

What do I have to do to make the session changes persistent?

I tried to use the web middleware but I get the message

ReflectionException in Container.php line 741: Class web does not exist



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire