Level 73
Have you tried using the facade?
Auth::login($user);
And just as a side note, you should validate the request before you try to do anything else, so I would move the validation line as a first line in the method.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
We have a page with a verification code that redirects to this page after the user logs in. I want to login after clicking the user confirmation button.
public function send(Request $request)
{
$user = User::whereCode($request->code)->whereMobile($request->mobile)->first();
if($user){
$user->verification_code = 1;
$user->save();
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
} else {
return redirect()->back();
}
}
Have you tried using the facade?
Auth::login($user);
And just as a side note, you should validate the request before you try to do anything else, so I would move the validation line as a first line in the method.
Please or to participate in this conversation.