NewUser2
NewUser2

Reputation: 117

How do I override the email field when resetting passwords?

I'm trying to reset a password using Laravel built-in function. I know that it's possible to define a specfic password resetter using this:

public function broker()
{
    return Password::broker('name');
}

But I would like to know if there's any way to do the same thing with the email field because my field has a different name and I get an SQL error.

Upvotes: 2

Views: 240

Answers (1)

mdexp
mdexp

Reputation: 3567

The trait CanResetPassoword, used by Laravel's Authenticatable class extended by the default User model, defines the method getEmailForPasswordReset().

Assuming that you want to override that field for the User model, you can override it to return the proper value:

/**
 * Get the e-mail address where password reset links are sent.
 *
 * @return string
 */
public function getEmailForPasswordReset()
{
    // Return the correct field value here
    return $this->email;
}

Upvotes: 2

Related Questions