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);
}
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 - Does not Session::put('mobile',$mobile) need this?
@IRANKHOSRAVI - I guess you want to pass in the $request->mobile there: Session::put('mobile', $request->mobile)
@JOHNBRAUN - Yes
Edit:
The next form is verification code. I want to save mobile for next form.
Hello @irankhosravi
session put in your controller like this :
Session()->put('mobile', $moble);
Get session value :
session()->get('mobile')
Hi @MAHAVEER - The next form is verification code. I want to save mobile for next form.
You should get the mobile from the user model rather than saving it in session?
@irankhosravi
I'm not understood what do want?
I think do you want mobile no in form input filed?
@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.