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

ManoMahe's avatar

Session value got null after the page reloads in Laravel 9

Hi there!

I have created a page with a simple form view of containing mobile number input. After submitting the form I have put that mobile number into a session and tried to render back to same view file with custom flash message. Here I can able to see the message, but the mobile number session got null always.

// session(['verify_mobile' => $request->mobile]); // Tried this way alos
// dd(session('verify_mobile'));

Session::put('verify_mobile', $request->mobile);
// dd(Session::get('verify_mobile')); // Here I can able to see the session value correctly

redirect()->back()->with('message', 'Mobile number stored..!');

After redirect back to same page leads me into null for the same session variable

<p>Your Mobile Number : {{ Session::get('verify_mobile') }} </p>

Don't get why, the above Session::get('verify_mobile') always returns null

0 likes
6 replies
vincent15000's avatar

It should work.

Don't you have any middleware or other code that could initialize the session ?

ManoMahe's avatar

@vincent15000 I don't get why this was happened, I just left my system alone for a while then re-tried, now it's working fine. :-<

vincent15000's avatar

@Thet Naing It's just another way to use the sessions : either via the facade Session::get(), or via the helper session(). Both will give the same result.

Please or to participate in this conversation.