我正在尝试在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": "/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
进行测试。
答案 0 :(得分:3)
同样有同样的问题,我通过在config文件夹中的auth.php文件中将我的默认防护设置为'web'来解决它。
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
请记住,您的路由不应该有此登录的auth中间件,因为,这只是为了进行身份验证。