use this
for registration
session( [ 'key' => 'value' ] );
for retrieval
$va = session('key');
e.g.
$value = 214;
session( [ 'company_id' => $value] );
echo session('company_id');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey all;
I have a service provider which writes down a piece of data at a slug and when I call the slug it returns the data. To persist the data in the session I use session(['slug' => 'some data']) BUT it does not return this slug unless I use session()->save() in the service provider. When I use session()->save() then all the session starts to persist, the flashed data does not go away or change at all, error messages never reset, etc. It looks like I took a snapshot of the current state of the system.
Is there a way to put data in session without calling save() or how can I defeat this problem?
Thanks a lot.
Please or to participate in this conversation.