I'm working on Laravel 9 and I have notices something that I've never seen before.
Basically I'm trying to make a Login system with Laravel 9 and for the next step of logging users in, I added an input to check for the user mobile phone number:
<input type="text" name="userinput" class="form-control" id="phone">
And at the Controller:
$findUser = User::where('usr_mobile_phone',$request->userinput)->first();
if($findUser){
Session::put('userData',$findUser);
return redirect()->route('auth.login.next');
}else{
return redirect()->back()->withErrors('No results!');
}
So as you can see I have send the userData
object information to the Session called userData
.
And then for the next Controller method that repsonses to auth.login.next
route, I added this:
public function loginNext()
{
$user = Session::get('userData');
if(Session::has('nextStep') && Session::get('nextStep') == 1){
return view('frontend.auth.next', compact('user'));
}else{
abort(404);
}
}
Now here, I tried inserting all the object of user to $user
variable.
So that in the next.blade.php
, I can check informations like this:
@if(!empty($user->usr_password_hash))
// Show button login with password
@endif
So it work nice and clean but there is only one problem:
If I stay at the same page and update the record of returned $user
manually in the phpmyadmin and set the usr_password_hash
to NULL
So the record will be looked like:
Now the button must not be appeared on the page because this password field is empty. However it is still showing!
So this means that session has sent the user object for only one time and this user object is not prototyping live of the user data from the DB.
However if I dd($user)
at the Controller method, I can properly get the user information:
So what's going wrong here?