Php Laravel JWT验证错误
我试图在Laravel 5.2中实现JWT,但我遇到了以下错误:Php Laravel JWT验证错误,php,laravel,jwt,dingo-api,Php,Laravel,Jwt,Dingo Api,我试图在Laravel 5.2中实现JWT,但我遇到了以下错误: "message": "call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\\Auth\\TokenGuard' does not have a method 'once'", "status_code": 500, "debug": { "line": 288, "file": "/hom
"message": "call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\\Auth\\TokenGuard' does not have a method 'once'",
"status_code": 500,
"debug": {
"line": 288,
"file": "/home/vagrant/Code/lsupport/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php",
"class": "ErrorException",
我的路由文件:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1',function($api)
{
$api->post('login','App\Http\Controllers\Auth\AuthController@authenticate');
});
我的AuthController:
public function authenticate(Request $request)
{
$credentials = $request->only('email','password');
try {
if(!$token = JWTAuth::attempt($credentials)) {
return $this->response->error(['error' => 'User credentials are not correct!'],401);
}
} catch(JWTException $ex) {
return $this->response->error(['error' => 'Something went wrong!'],500);
}
return $this->response->item(compact('token'));
}
我正在用postman进行测试,也遇到了同样的问题,我通过在config文件夹中的auth.php文件中将我的默认保护设置为“web”解决了这个问题
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
请记住,您的路由不应为此登录使用auth中间件,因为这只是为了进行身份验证。谢谢!!那太有用了!