I have a weird problem where sometimes sessions won’t be stored, either using the helper or the $request->session()->put(...);
method.
For example, I have a simple controller method that returns a view and also stores a default session value if it doesn’t exist yet:
public function my_view(Request $request)
{
if(!$request->session()->has('my_session')) {
$request->session()->put('my_session', 'default_value');
}
.. some code ..
return view('my_view');
}
Then, in the view above, I have a button that calls another method in the controller, which uses that session value:
public function some_action(Request $request)
{
$my_session_value = $request->session()->get('my_session'); // null
// need to use $my_session_value but it's null sometimes!
}
But the session value returns null
, and after refreshing the view a few times, or clicking a button in the view that updates that session value, it would work.
And it doesn’t happen all the time, but it does happen many times after the initial page load
What could cause that?
*The app was updated from Laravel 7 to 10 in the past if that matters