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

mozew's avatar
Level 6

How to get mobile number in session of laravel?

My project is, after a user come registered redirect to verification page. Only I want to get Session of mobile number.

public function register(Request $request)
{
    Session::put('mobile',$mobile) 
    $code = rand(10000,99999);
    $user = User::create([
        'first_name' => $request->first_name,
        'last_name' => $request->last_name,
        'gender' => $request->gender,
        'mobile' => $request->mobile,
        //continue code
    }
    return redirect()->route('verification/?session'.$session);
}
0 likes
9 replies
JohnBraun's avatar

Session data can be retrieved by calling the session() helper and passing in the key you want to return. In your case that would be session('mobile').

$mobile = session('mobile');

How to work with sessions is very nicely documented: https://laravel.com/docs/5.8/session

JohnBraun's avatar

@IRANKHOSRAVI - I guess you want to pass in the $request->mobile there: Session::put('mobile', $request->mobile)

mozew's avatar
Level 6

@JOHNBRAUN - Yes

Edit:

The next form is verification code. I want to save mobile for next form.

Mahaveer's avatar

Hello @irankhosravi

session put in your controller like this :

Session()->put('mobile', $moble);

Get session value :

session()->get('mobile')
mozew's avatar
Level 6

Hi @MAHAVEER - The next form is verification code. I want to save mobile for next form.

Snapey's avatar

You should get the mobile from the user model rather than saving it in session?

Robstar's avatar

@MAHAVEER - This is all extremely bread and butter stuff that can be explained by reading the Laravel docs.

In your controller, when processing the post:

session()->put('mobile', $request->mobile);

Then elsewhere:

$mobile = session()->get('mobile');

In the latter instance you'd need to validate / sanitise any data you fetch from the session.

Please or to participate in this conversation.