Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahidkarimi's avatar

Sessions are not saving : Bug in Laravel core

session()->put('currency', $currency);

session()->save();

If I immediately dd the session it shows the new value. But in another place, it shows the old value means not saving. I have been facing this issue with every Laravel project.

I tried with all session drivers, redis, array, file and databse. Anybody, please give a permanent solution of this issue.

0 likes
13 replies
Alamin's avatar

Can you try something like this

<?php

use Illuminate\Support\Facades\Session;    

class XyController extends Controller{    

public function X()    
{
     Session::put('currency', $currency); /* to set session */
             Session::get('currency');    /* to read session data  */
}     
 }       

 ?>           
shahidkarimi's avatar
shahidkarimi
OP
Best Answer
Level 1

Not working, for sure its a bug. I face this in every project. For the first request, it works. But when the page is refreshed it don't work

jlrdw's avatar

If you refresh page ???????? Is anything passed to $currency? A modern web app shouldn't be refreshing a page. Rather on each request go through proper view and route to properly pass the necessary data along.

If you are using ajax, DO NOT use session with ajax.

I use sessions often in ver 5.5, and never had a problem.

2 likes
shahidkarimi's avatar

Once something saved in the session it should be persistent. Yes of course on refreshing it should be there. I am not using ajax. Example: Goto Fiverr.com on the bottom right side there is currency dropdown. Change that and see, the page refreshes and sets that currency in session.

1 like
jlrdw's avatar

Where is $currency coming from?

I set a search like

Session::put('dogsearch', $dogsearch);

And I use it after an edit to return to page I left off on (part of query string). 100% works.

You are some how passing a variable at the wrong time / place, thus the session isn't properly updating.

@topvillas the static method also works 100% for me. Taylor uses __callStatic().

shahidkarimi's avatar

$currency is coming from form input field. $currency = Input::get('currency')

jlrdw's avatar

And it works if a form is submitted, right?

arcadia_1's avatar

I think this is the best answer.

When dd() dump the data, i think, is like print_r and die().

murilo's avatar

I had same problem in Laravel 6 , maybe in Laravel 7 it is solved .

alekseyshavrak's avatar

Maybe you are trying to write a value before it starts session. I suppose that many do this in the AppServiceProvider.

Worked for me when transferred logic from the AppServiceProvider to middleware

Please or to participate in this conversation.