The best way to work with sessions is simply passing them to the request.
See this example in the docs: https://laravel.com/docs/5.3/session#using-the-session
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I've been asking on SO as I have freshly installed Laravel 5.3, and followed the documentation on storing data in session. Here is the post for background - http://stackoverflow.com/questions/41633766/laravel-session-out-the-box-not-working/41633962
In conclusion, it seems I need to do this:
Session::put('key', md5(rand())); // this alone won't write to session
Session::save(); // this call is required in addition to put()
So far it would seem that I need to call Session::save() after each cycle to ensure that data is written to session (file, db, etc). However, I see no mention of this in the Laravel docs on sessions. Isn't this save be done automatically at the end? Otherwise, if it is required, where should I put it in the app? Should I create middleware that calls Session::save() once the dispatch cycle is complete?
Please or to participate in this conversation.