Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel's Session flush and forget methods not working as expected

I tried to delete a value from my session using :

Session::forget('value')

but it didn't delete!

However, when i tried using save method like so :

 Session::forget('value')
 Session::save()

it worked! (I.e. the value was deleted from the session.)

Please - what am I doing wrong? I don't see the save method in the Laravel documentation when using Session::flush() and Session::forget().

like image 408
Ewomazino Ukah Avatar asked Oct 04 '16 16:10

Ewomazino Ukah


2 Answers

The save() method will actaully perform the write to the file.

It seems that your application doesn't call Session::save() before it outputs content to the user on all requests.

If this method isn't called, the Session file will not get updated with the new values, and they will still be there on the next visit.

It's important to always call Session::save() if you wish to be sure stuff got removed or added and the change persists.

like image 60
Tschallacka Avatar answered Sep 19 '22 11:09

Tschallacka


Full cache clear (either using command-line or code):

php artisan cache:clear
Artisan::call('cache:clear');

+ Full session flush:

Session::flush();

through this method you can clear all of your session data.

like image 40
Rizwan Saleem Avatar answered Sep 18 '22 11:09

Rizwan Saleem