4
votes

I am new to Lumen and just tried to create an app. I am getting an error that states at Application->Laravel\Lumen\Concerns{closure}(8, 'Undefined variable: app', '/Users/test/Sites/books/routes/web.php', 14, array('router' => object(Router))) when I try to use this bit of code:

$app->group(['prefix' => 'book/'], function() use ($app) {
    $app->get('/','BooksController@index'); //get all the routes    
    $app->post('/','BooksController@store'); //store single route
    $app->get('/{id}/', 'BooksController@show'); //get single route
    $app->put('/{id}/','BooksController@update'); //update single route
    $app->delete('/{id}/','BooksController@destroy'); //delete single route
});

According to the documents https://lumen.laravel.com/docs/5.5/routing this should work. I am following a tutorial found at https://paulund.co.uk/creating-a-rest-api-with-lumen I know that 5.5 just came out a few days ago, so there might not be anyone that knows the answer yet, but any help would be appreciated.

2

2 Answers

13
votes

There seems some undocumented change. You need to change $app into $router as follow:

$router->group(['prefix' => 'book/'], function() use ($router) {
    $router->get('/','BooksController@index'); //get all the routes    
    $router->post('/','BooksController@store'); //store single route
    $router->get('/{id}/', 'BooksController@show'); //get single route
    $router->put('/{id}/','BooksController@update'); //update single route
    $router->delete('/{id}/','BooksController@destroy'); //delete single route
});
2
votes

As misbachul munir said, $app changed to $router.

But you have to, at least, update your references in bootstrap/app.php and routes/web.php. Check the files, you do not have to do a simple search-and-replace because it only needs to change in some places.

For example, $app->version() is now $router->app->version()

EDIT: It is in the docs https://lumen.laravel.com/docs/5.5/upgrade under "Updating The Bootstrap File"