我正在使用React构建一个Laravel App作为API。使用护照授予Oauth时,我想将默认的身份验证字段“电子邮件”更改为“用户名”字段。在不更改Laravel AuthenticatesUser特性的情况下最好的方法是什么。
在您的用户模型中,您可以添加以下方法来通过用户名而不是电子邮件登录:
/**
* Find the user instance for the given username.
*
* @param string $username
* @return \App\User
*/
public function findForPassport($username)
{
return $this->where('username', $username)->first();
}
https://laravel.com/docs/7.x/passport#customizing-the-username-field