Here's config/session.php
:
return [
'driver' => 'file',
'files' => storage_path().'/framework/sessions',
];
My storage/framework/sessions
have 755 permissions.
When I put these 2 line in my controller
Session::set('aa', 'bb');
dd(Session::get('aa'));
I receive expected "bb"
output. But if I comment first line:
// Session::set('aa', 'bb');
dd(Session::get('aa'));
and refresh page, I still expecting "bb"
but getting null
.
Also, storage/framework/sessions
is empty.
What should I do to make Session working?
With laravel 5.*, you must change the kernel file like bellow:
then go to storage/framework/session folder and change the permission to 755 if it has another amount, then delete all files in your storage/framework/session path, use your code again to put something in a session, watch the storage/framework/session folder.
If your session work you can see the weird long file that belong to session right now, and you are done!
If your problem is not yet solved, go to config/session and change:
to another predefined amount like:
or even
and finally if you have an empty folder of storage/framework/session, you still have a problem for sure !!!
Laravel 5 handles sessions via a middleware class called
StartSession
. More importantly, this middleware is aTerminableMiddleware
and the code that actually saves the data (in your case to the session file) is located in theterminate
method, which is run at the end of the request lifecycle:When calling
dd(Session::get('aa'));
the request is being interrupted before theterminate
method of the middleware can be called.Funnily enough, the Laravel Middleware Documentation actually explains Terminable Middleware logic by giving the Laravel
StartSession
middleware as an example:That being said, try using
var_dump()
instead of usingdd()
.