laravel5.4 TokenGuard.php
文件里,通过设置生成的token的格式,判断有误token有无过期。
但是走 return response()->json();时,没有返回 ['status'=>2, 'message'=>'failure', 'data'=>'登录超时'],我想获得 response
数据
public function user()
{
// If we've already retrieved the user for the current request we can just
// return it back immediately. We do not want to fetch the user data on
// every call to this method because that would be tremendously slow.
if (! is_null($this->user)) {
return $this->user;
}
$user = null;
$token = $this->getTokenForRequest();
if (! empty($token)) {
// 新增 判断api_token的时效性
// api_token事例: PuQHMX7sgqjJ1Dx0d9uOosHjO6QCxECP_1505093728
if(!LoginService::TokenIsValid($token)) {
return response()->json(['status'=>2, 'message'=>'failure', 'data'=>'登录超时'], 200);
}
$user = $this->provider->retrieveByCredentials(
[$this->storageKey => $token]
);
}
return $this->user = $user;
}
代码贴出:
麻烦大家 帮我看下,谢谢!!