3

I'm using Laravel 5.2 and sessions don't seem to be saving.

I've tried both file and database (after creating the sessions table) and neither seem to work.

I've set the file permissions to 777 on storage/framework/sessions and no sessions file is created.

To save a session I'm using:

session(['key' => 'value']);

and to retrieve the session I'm using:

$value = session('key');

But I can't get it to save

Pankaj
  • 9,749
  • 32
  • 139
  • 283
nvaughan84
  • 463
  • 6
  • 13

2 Answers2

5

Ok i had a similar problem but i was already using the 'web' middleware. It turns out that if you are calling die() or dd() before your script has finished executing then your session will not persist!!

See Laravel session data not sticking across page loads

omarjebari
  • 4,861
  • 3
  • 34
  • 32
0

As already answered in here: https://stackoverflow.com/a/34454031/5781420, be sure to assign the "web" middleware to your route or your controller.

You can do this via a Route::group(...);, or just a Route::?(...)->middleware('web'); or even in the controller constructor itself by $this->middleware('web');

Community
  • 1
  • 1
tinyoverflow
  • 1,933
  • 3
  • 13
  • 29