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

ajithlal's avatar

Session not returning the saved data on page refresh

I'm using session to store some data. I've a session named searchData, that is an array. it is having values

Array ( [Event] => 5 [Hall] => 5 [Date] => 2019-06-25 [Time] => Array ( [0] => Day ) )

I'm trying to add another array of values into the existing array, after adding the values it is returning the new values inside the array like below

[searchData] => Array
                (
                    [event] => 5
                    [hall] => 5
                    [date] => 2019-06-25
                    [time] => Array
                        (
                            [0] => day
                        )

                    [package_id] => 1
                    [price] => 6300
                    [advance] => 3000
                    [selectedPrice] => 3000
                    [add-on] => Array
                        (
                            [5-id] => 5
                            [5-price] => 100.0000
                            [5-count] => 1
                        )

                )

when I refresh the page and print the values in session the newly added array is not showing.

Here is the code used for adding the array of values to existing session.

    $request->session()->put("searchData.add-on.{$addOn->id}-id", $addOn->id);
        $request->session()->put("searchData.add-on.{$addOn->id}-price", $addOn->price);
        $request->session()->put("searchData.add-on.{$addOn->id}-count", $request->count);

in my config/session.php i've changed the below section

'expire_on_close' => true,
0 likes
1 reply
aurawindsurfing's avatar

Hi @ajithlal

expire_on_close should have nothing to do with it, have a read here: https://laracasts.com/discuss/channels/laravel/session-expire-on-close

Just as the simplest approach try not to amend the existing array on your session.

  1. Get array from session and put in in variable.
  2. Delete it from session.
  3. Append variable with what you need.
  4. Put it back in session.

Now you can be sure there is only one and correct in the session.

Of that does not work then your problem is elsewhere.

Please or to participate in this conversation.