2016-04-23 10 views
1

Ich versuche JWT in Laravel 5.2 zu implementieren, aber ich bekomme diese Fehlermeldung:Laravel JWT Auth Fehler

"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", 

Meine Routen-Datei:

$api = app('Dingo\Api\Routing\Router'); 

$api->version('v1',function($api) 
{ 
    $api->post('login','App\Http\Controllers\Auth\[email protected]'); 
}); 

Mein 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')); 
    } 

Ich teste mit postman.

Antwort

3

Auch hatte das gleiche Problem, löste ich es, indem ich meine Standard-Wache auf "Web" in der Auth.php-Datei im Config-Ordner gesetzt.

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

Denken Sie daran, Ihre Route für diese Anmeldung die Auth-Middleware nicht haben sollte, weil dies nur zu authentifizieren ist.

+0

Vielen Dank !! Das ist so hilfreich! – Jamie

+0

hat auch für mich funktioniert! –