Laravel Passeport 将用户电子邮件身份验证更改为用户名
Laravel Passeport change user email authentication to username
我正在使用 React 构建 Laravel 应用 API。我想在使用护照授予 Oauth 时将默认身份验证字段 'email' 更改为 'username' 字段。在不更改 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
我正在使用 React 构建 Laravel 应用 API。我想在使用护照授予 Oauth 时将默认身份验证字段 'email' 更改为 'username' 字段。在不更改 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