Route Group in Lumen error Call to undefined method Laravel\Lumen\Application::group()

Shakti Phartiyal picture Shakti Phartiyal · Sep 21, 2017 · Viewed 9.5k times · Source

I have declared a route group in laravel/lumen like so:

$app->group(['middleware' => 'auth'], function () use ($app) {
    $app->get('/details', 'UserController@details');
});

all contents of route file web.php are like so:

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app = app();

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


$app->group(['middleware' => 'auth'], function () use ($app) {
    $app->get('/details', 'UserController@details');
});

on making a call to http://THE_URL/

I get an error Call to undefined method Laravel\Lumen\Application::group()

ERROR

How do I add route group with a middleware ?

Answer

zedomel picture zedomel · Nov 22, 2018

Actually as @Aine said in Lumen 5.5+ you should change:

LumenPassport::routes($this->app);

to

LumenPassport::routes($this->app->router);

Application does not have group() method anymore.

thanks