不知道该怎么去改,然后在TokenGuard.php
中加了代码,
public function user()
{
if ( !is_null($this->user) ) {
return $this->user;
}
$user = null;
$token = $this->getTokenForRequest();
if ( !empty($token) ) {
$user = $this->provider->retrieveByCredentials(
[$this->storageKey => $token]
);
}
// 这个条件语句是自己加的
if ( $user->expired_at->lt(Carbon::now()) ) {
return collect(['Token has expired.']);
}
return $this->user = $user;
}
虽然实现了 api_token 过期的效果,但是这样写,感觉很不好