* Generate a token for a given subject.
* @param \Tymon\JWTAuth\Contracts\JWTSubject $subject
* @return string
public function fromSubject(JWTSubject $subject)
$payload = $this->makePayload($subject);
return $this->manager->encode($payload)->get();
* Alias to generate a token for a given user.
* @param \Tymon\JWTAuth\Contracts\JWTSubject $user
* @return string
public function fromUser(JWTSubject $user)
return $this->fromSubject($user);
这两个方法没看出来有什么区别,应该只是为了兼容之前的老版本而保留。
解决方法就是 修改系统的user model,调用jwt的一个
JWTSubject
接口,
namespace Tymon\JWTAuth\Contracts;
interface JWTSubject
* Get the identifier that will be stored in the subject claim of the JWT.
* @return mixed
public function getJWTIdentifier();
* Return a key value array, containing any custom claims to be added to the JWT.
* @return array
public function getJWTCustomClaims();
并实现接口中的两个方法:
namespace App\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends authenticatable implements JWTSubject
* Get the identifier that will be stored in the subject claim of the JWT.
* @return mixed
public function getJWTIdentifier()
return $this->getKey();
* Return a key value array, containing any custom claims to be added to the JWT.
* @return array
public function getJWTCustomClaims()