laravel-jwt attempt()异常问题处理
作者:互联网
文章目录
laravel-jwt attempt()异常问题处理
追踪源码发现,用户表密码字段必须是 password,否则会一直返回false,因为如果密码字段不是password,则认为该字段也是查询条件,用于查询数据,肯定查不出数据。
原文件路径:vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
public function retrieveByCredentials(array $credentials)
{
if (empty($credentials) ||
(count($credentials) === 1 &&
Str::contains($this->firstCredentialKey($credentials), 'password'))) {
return;
}
// First we will add each credential element to the query as a where clause.
// Then we can execute the query and, if we found a user, return it in a
// Eloquent User "model" that will be utilized by the Guard instances.
$query = $this->newModelQuery();
foreach ($credentials as $key => $value) {
if (Str::contains($key, 'password')) {
continue;
}
if (is_array($value) || $value instanceof Arrayable) {
$query->whereIn($key, $value);
} else {
$query->where($key, $value);
}
}
return $query->first();
}
标签:laravel,attempt,jwt,value,key,query,credentials,password 来源: https://blog.csdn.net/dmt742055597/article/details/117531659