Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen-passport throws FatalThrowableError - Call to undefined method Laravel\Lumen\Application::group() #69

Closed
marvinjude opened this issue Feb 14, 2018 · 3 comments · Fixed by #173

Comments

@marvinjude
Copy link

i followed all the steps in the docs but i can't still get lumen passport to work,
i keep getting this error:

(1/1) FatalThrowableError
    Call to undefined method Laravel\Lumen\Application::group()

my routes/web.php looks like so

<?php

$router->get('/', function () use ($router) {
    return $router->app->version();
});

 $router->group(['middleware' => 'auth:api'], function () use ($router) {
    $router->get('/user', 'UsersController@all');
    $router->get('/user/{id}', 'UsersController@get');
    $router->post('/user', 'UsersController@add');
    $router->put('/user/{id}', 'UsersController@put');
    $router->delete('/user/{id}', 'UsersController@remove');
});

my app/provider/AuthServiceProvider.php

    public function boot()
    {
   
              LumenPassport::routes($this->app);
    }
}

my bootstrap/web.php looks like this

<?php

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

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



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

$app->configure('auth');

$app->withFacades();

$app->withEloquent();



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

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



// $app->middleware([
//    App\Http\Middleware\ExampleMiddleware::class
// ]);

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



$app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);

$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);

Dusterio\LumenPassport\LumenPassport::routes($app);
Dusterio\LumenPassport\LumenPassport::routes($app, ['prefix'=> 'api/v1']);



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

return $app;

config/auth.php

<?php 
return
[ 'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
 
    'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],
 
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\Models\User::class
        ]
    ]
];
@varyandeveloper
Copy link

Hey! You should send $this->app->router instead of $this->app because group method dose not exists for Laravel\Lumen\Application class.

public function boot() { LumenPassport::routes($this->app->router); }

So I Belive this will fix your issue.

@lloricode
Copy link
Contributor

same here

@lloricode
Copy link
Contributor

@varyandeveloper thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants