dusterio / lumen-passport

Making Laravel Passport work with Lumen
MIT License
655 stars 138 forks source link

Call to undefined method Illuminate\Auth\RequestGuard::handle() #5

Closed hboykier closed 7 years ago

hboykier commented 7 years ago

When trying to use midleware auth:api on a route I receive the error

FatalThrowableError in AuthManager.php line 294: Call to undefined method Illuminate\Auth\RequestGuard::handle() in AuthManager.php line 294 at AuthManager->__call('handle', array(object(Request), object(Closure), 'api')) in Pipeline.php line 137 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Laravel\Lumen\Routing{closure}(object(Request)) in Pipeline.php line 104 at Pipeline->then(object(Closure)) in RoutesRequests.php line 647 at Application->sendThroughPipeline(array('auth:api'), object(Closure)) in RoutesRequests.php line 400 at Application->dispatch(null) in RoutesRequests.php line 341 at Application->run() in index.php line 28

dusterio commented 7 years ago

Did you register Laravel\Passport\PassportServiceProvider in your boot process? handle() is a method on middleware, not on guard. can you show your route from routes.php?

hboykier commented 7 years ago

This is what I added in my bootstrap\app.php:

$app->routeMiddleware([ 'auth' => App\Http\Middleware\Authenticate::class, ]); $app->register(Laravel\Passport\PassportServiceProvider::class); $app->register(Dusterio\LumenPassport\PassportServiceProvider::class);

And these are my routes at routes.php:

$app->group(['prefix' => 'admin', 'namespace' => 'App\Http\Controllers\admin'], function() use ($app) { $app->get('/domain', 'DomainsController@index')->middleware('auth:api'); $app->get('/domain/{id}', 'DomainsController@show'); $app->post('/domain', 'DomainsController@store'); $app->put('/domain/{id}', 'DomainsController@update'); $app->delete('/domain/{id}', 'DomainsController@destroy'); });

hboykier commented 7 years ago

Solved using the middleware as this: $app->get('/domain', ['uses' => 'DomainsController@index', 'middleware' => ['auth']]);