Not able to put/get value from session during Ajax request in Laravel 8

Viewed 139

We have two ajax request in same webpage.

In first Ajax request we put some value in the session against the key product_id.

$request->session()->put('product_id', 'value'); 

In second Ajax request we try to get value of product_id from session but it returns null or blank

$request->session()->get('product_id'); // Returns null

I'm able to retrieve the value of product_id from session if I try to get it just after putting it into session.

  1. I'm using jQuery to make ajax calls, Both the ajax request use post method.
  2. My routes are in web.php
  3. I've checked the session id in both request it's the same. The code for getting and setting session data is in same controller file.
  4. I'm using database as a session driver.

Can anyone please help me identify the issue as why I'm not able to retrieve product_id from session in second ajax call? Issue is not consistent on some pages.

IMPORTANT : Recently we have upgraded the Laravel version from 5.7 to 8.40. It's working fine in older version.

0 Answers
Related