Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Lumen 5.5 Project 'Undefined variable: app'

Tags:

php

lumen

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.

like image 690
Devsterefic Avatar asked Dec 05 '22 13:12

Devsterefic


1 Answers

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
});
like image 157
misbachul munir Avatar answered Dec 24 '22 03:12

misbachul munir