1 回答

TA貢獻1796條經驗 獲得超7個贊
我找到了問題的解決方案。這是我的錯誤,因為我的User.php模型中有拼寫錯誤
變更前型號:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'verified', 'balance', 'isAdmin',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'verified',
];
/**
* getJWTCustomClaims
*
* @return mixed
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* getJWTIdentifier
*
* @return array
*/
public function getJWTIdentifier()
{
return $this->key;
}
/**
* RelationShip between user, and user activation token
*
* @return void
*/
public function verifyToken()
{
return $this->hasOne(UserVerification::class);
}
}
變更后型號:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'verified', 'balance', 'isAdmin',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'verified',
];
/**
* getJWTCustomClaims
*
* @return mixed
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* getJWTIdentifier
*
* @return array
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* RelationShip between user, and user activation token
*
* @return void
*/
public function verifyToken()
{
return $this->hasOne(UserVerification::class);
}
}
所以我將getJWTIdentifier()返回從更改$this->key為$this->getKey()
- 1 回答
- 0 關注
- 112 瀏覽
添加回答
舉報