2016-05-25 14 views
3

Hey, also habe ich gerade auf Lumen 5.2 aktualisiert und stieß auf Probleme mit JWT-Auth. Ich habe alle Anweisungen befolgt und meine app.php-Datei einschließlich aller Middleware aktualisiert. Ich auch Komponist benötigt Beleuchtung/Routing und beleuchten/Auth. Allerdings erhalte ich die Fehlermeldung:Lumen: Method Handle existiert nicht mit jwt-auth, machte die Middleware

BadMethodCallException in Macroable.php line 81: Method handle does not exist. in Macroable.php line 81 at ResponseFactory->__call('handle', array(object(Request), object(Closure)))

Ich kann keinen Sinn aus diesem Fehler zu erhalten scheinen?

Hier ist meine Bootstrap/app.php Referenz:

<?php 

require_once __DIR__.'/../vendor/autoload.php'; 

try { 
    (new Dotenv\Dotenv(__DIR__.'/../'))->load(); 
} catch (Dotenv\Exception\InvalidPathException $e) { 
    // 
} 

/* 
|-------------------------------------------------------------------------- 
| Create The Application 
|-------------------------------------------------------------------------- 
| 
| Here we will load the environment and create the application instance 
| that serves as the central piece of this framework. We'll use this 
| application as an "IoC" container and router for this framework. 
| 
*/ 

//$app = new Laravel\Lumen\Application(
// realpath(__DIR__.'/../') 
//); 

// For nested route groups to work 
$app = new Fremail\NestedRouteGroups\Application(
    realpath(__DIR__.'/../') 
); 

$app->withFacades(); 

$app->configure('jwt'); 
$app->configure('auth'); 

class_alias(Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTAuth'); 
class_alias(Tymon\JWTAuth\Facades\JWTFactory::class, 'JWTFactory'); 


$app->withEloquent(); 

/* 
|-------------------------------------------------------------------------- 
| Register Container Bindings 
|-------------------------------------------------------------------------- 
| 
| Now we will register a few bindings in the service container. We will 
| register the exception handler and the console kernel. You may add 
| your own bindings here if you like or you can make another file. 
| 
*/ 

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class, 
    App\Exceptions\Handler::class 
); 

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class, 
    App\Console\Kernel::class 
); 

$app->singleton(
    Illuminate\Cache\CacheManager::class, 
    function ($app) { 
     return $app->make('cache'); 
    } 
); 

$app->singleton(
    Illuminate\Auth\AuthManager::class, 
    function ($app) { 
     return $app->make('auth'); 
    } 
); 

$app->singleton(
    Illuminate\Contracts\Routing\ResponseFactory::class, 
    Illuminate\Routing\ResponseFactory::class 
); 


/* 
|-------------------------------------------------------------------------- 
| Register Middleware 
|-------------------------------------------------------------------------- 
| 
| Next, we will register the middleware with the application. These can 
| be global middleware that run before and after each request into a 
| route or middleware that'll be assigned to some specific routes. 
| 
*/ 

$app->middleware([ 
    Illuminate\Contracts\Routing\ResponseFactory::class, 
//  // Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
//  // Illuminate\Session\Middleware\StartSession::class, 
//  // Illuminate\View\Middleware\ShareErrorsFromSession::class, 
// Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class, 
]); 

// Middleware for authentication for the API 
$app->routeMiddleware([ 
    'auth'  => App\Http\Middleware\Authenticate::class, 
    'jwt.auth' => Tymon\JWTAuth\Middleware\GetUserFromToken::class, 
    'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class, 
]); 

/* 
|-------------------------------------------------------------------------- 
| Register Service Providers 
|-------------------------------------------------------------------------- 
| 
| Here we will register all of the application's service providers which 
| are used to bind services into the container. Service providers are 
| totally optional, so you are not required to uncomment this line. 
| 
*/ 

$app->register(App\Providers\GuardServiceProvider::class); 
$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class); 

/* 
|-------------------------------------------------------------------------- 
| Load The Application Routes 
|-------------------------------------------------------------------------- 
| 
| Next we will include the routes file so that they can all be added to 
| the application. This will provide all of the URLs the application 
| can respond to, as well as the controllers that may handle them. 
| 
*/ 

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) { 
    require __DIR__.'/../app/Http/routes.php'; 
}); 

return $app; 

Danke für Ihre Hilfe

+0

In Laravel, die Methode, die diese Ausnahme wirft versucht, dynamisch, um Anrufe zu einer Klasse zu behandeln ... können Sie bestätigen, es ist das gleiche in Lumen? Es scheint, dass etwas 'handle()' für eine Klasse aufruft, aber die Methode existiert in dieser Klasse nicht. – camelCase

+0

Ja, ich denke, das passiert im Grunde auch hier. Etwas versucht, 'handle' in ResponseFactory aufzurufen, aber es existiert nicht. http://imgur.com/SIKYA52 –

+0

können Sie den fehlerhaften Code anzeigen, der den Fehler verursacht? – Feek

Antwort

4

Meine Antwort muss spät sein, aber für zukünftige Googler, hier ist, wie ich es gelöst (Lumen 5.3):

$app->routeMiddleware([ 
    'auth' => App\Http\Middleware\Authenticate::class 
]); 
+0

Mein Tag gerettet! Vielen Dank! – basagabi

+0

Wahrscheinlich ein Tag meines Lebens gerettet .. – Sisir

0

ich traf auch th:

ich habe die auth-Middleware in Bootstrap/app.php gesetzt Die gleichen Fehler wie du.

Aber ich habe einen Fehler auf der Routing-Datei gemacht. Ich schreibe Routing-Dateien:

$app->middleware(['auth'],function()use($app){ 
    $app->group(['prefix'=>'pur'],function()use($app){ 
     $app->get('list','[email protected]'); 
    }); 
}); 

Das ist falsch. Routing sollte zuerst definiert werden:

$app->group(['middleware' => ['auth']], function() use ($app) { 
$app->group(['prefix'=>'pur'],function()use($app){ 
    $app->get('list','[email protected]'); 
}); 

});

Meine falsche Information:

enter image description here