新流明5.5项目'未定义变量:app'

Dev*_*fic 3 php lumen

我是Lumen的新手,只是试图创建一个应用程序.我收到一个错误,在Application-> Laravel\Lumen\Concerns {closure}(8,'Undefined variable:app','/ Users/test/Site/books /routes/web.php',14,array( 'router'=> object(Router)))当我尝试使用这段代码时:

$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
});
Run Code Online (Sandbox Code Playgroud)

根据文件https://lumen.laravel.com/docs/5.5/routing这应该工作.我正在关注https://paulund.co.uk/creating-a-rest-api-with-lumen上的教程我知道5.5几天前就出来了,所以可能没有人知道答案但是,任何帮助将不胜感激.

小智 10

似乎有一些无证的变化.你需要$app改成$router如下:

$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
});
Run Code Online (Sandbox Code Playgroud)