某些方法出现问题"一旦",是ORM问题吗?我不知道......
public function login(Request $request){
$validateData = Validator::make($request->all(), [
'email' => 'required',
'password' => 'required'
], ApiValidator::getMessages());
if($validateData->fails()){
$errors = $validateData->messages();
return response()->json(ApiValidator::response(array(), $errors), 400);
}
try {
if (!$token = $this->jwt->attempt($request->only('email', 'password'))) {
return response()->json(ApiValidator::response(array(), array('Bad credentials')), 401);
}
} catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
return response()->json(ApiValidator::response(array(), array('Token expired')), 401);
} catch (\Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
return response()->json(ApiValidator::response(array(), array('Token invalid')), 401);
} catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
return response()->json(ApiValidator::response(array(), array('Token absent' => $e->getMessage())), 401);
}
return response()->json(compact('token'));
}
我使用流明5.5 tymondesign / jwt-auth
答案 0 :(得分:0)
通过在应用的auth.php
目录中创建config
文件,确保您已为应用定义了身份验证保护。这就是我的样子:
return [
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
],
'guards' => [
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Models\User::class,
],
],
];