Just like the documentation shows:
https://laravel.com/docs/5.8/session#storing-data
I prefer the session facade myself:
use Illuminate\Support\Facades\Session;
then
Session::put('dogrows', $dogrows); // just example
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm trying to use Session in controller. Can the stored value in session be used in laravel controller ? I can store data to session from my controller but whenever I try this die(var_dump(Session::get('variable'))); It says undefined variable session. This is how I store my value in session -> Session::put('variable', $value); and this is how I get my data Session::get('variable');. The problem is can session get be used in different controller ? by just calling session::get('variable');
Yes of course.
If you dd() then session data is not written to the session unless you session()->save() before the dd. This is because session data is persisted to the session storage by terminable middleware and if you dd or your application crashes then the session data might not be saved.
install barryvhd/laravel-debugbar . It will show you the data stored in session after each http request.
Please or to participate in this conversation.