2016-04-23 18 views
1

私はLaravel 5.2でJWTを実装しようとしているが、私はこのエラーを取得:ファイルLaravel 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\[email protected]'); 
}); 

マイ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でテストしています。

答えて

3

同じ問題があったので、私はconfigフォルダ内のauth.phpファイルのデフォルトガードを 'web'に設定して解決しました。

'defaults' => [ 
    'guard' => 'web', 
    'passwords' => 'users', 
], 

これは単なる認証することで、ので、あなたのルートは、このログインの認証ミドルウェアを持つべきではない、覚えておいてください。

+0

ありがとうございます!それはとても役に立ちます! – Jamie

+0

も私のために働いた! –