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.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With