Laravel 身份验证更改列名称
Laravel Authentication change column name
我想将 table 'users' 中的列名 'email' 更改为 'username',laravel 框架使用它来进行身份验证用户。
我已经尝试过以下方法:
// LoginController.php
public function username()
{
return 'username';
}
// User.php
public function getAuthIdentifierName() {
return 'username';
}
但是如果我发出 HTTP 请求以通过密码获取新令牌(请参阅此处:https://laravel.com/docs/5.6/passport#password-grant-tokens),它总是以错误消息响应,指出无法找到列 'email' .
我必须 change/configure 哪些文件才能完成这项工作?
谢谢
如回答:
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
// ... some code
public function findForPassport($username) {
return $this->where('id', $username)->first();
}
}
我想将 table 'users' 中的列名 'email' 更改为 'username',laravel 框架使用它来进行身份验证用户。
我已经尝试过以下方法:
// LoginController.php
public function username()
{
return 'username';
}
// User.php
public function getAuthIdentifierName() {
return 'username';
}
但是如果我发出 HTTP 请求以通过密码获取新令牌(请参阅此处:https://laravel.com/docs/5.6/passport#password-grant-tokens),它总是以错误消息响应,指出无法找到列 'email' .
我必须 change/configure 哪些文件才能完成这项工作?
谢谢
如回答
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
// ... some code
public function findForPassport($username) {
return $this->where('id', $username)->first();
}
}