Search code examples
phplaravelauthenticationilluminate

Alter Request parameter(Email) and then Authenticate User in Laravel


I need to change the request parameter i.e. email, and then attempt login with the new email. What I am trying:

$user_handle = $request->email;
$gook = Gookarma::where('handle', '=', $user_handle)->firstOrFail();
$acc = Account::find($gook->karmable_id);
$request->email = $acc->email;
            
if ($this->attemptLogin($request)) {
    return $this->sendLoginResponse($request);
}

But it doesn't update the request, and login attempt goes with the previous email field input. Previous email I'm pulling up from API.

I tried with request->all() but when attempt login after the request update, it displays an error.


Solution

  • Creating a new variable of Request instance and assigning email and password from the previous request variable to the new variable worked for me.

    $req = new Request([$request]);
    $req['email']=$acc->email;
    $req['password'] = $request->password;