gpt4 book ai didi

php - 新流明5.5项目 'Undefined variable: app'

转载 作者:行者123 更新时间:2023-12-02 03:20:02 25 4
gpt4 key购买 nike

我是 Lumen 新手,只是尝试创建一个应用程序。我收到一条错误,指出 Application->Laravel\Lumen\Concerns{closure}(8, ' undefined variable : app', '/Users/test/Sites/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
});

根据文档https://lumen.laravel.com/docs/5.5/routing这应该有效。我正在遵循 https://paulund.co.uk/creating-a-rest-api-with-lumen 中找到的教程我知道 5.5 几天前刚刚发布,所以可能还没有人知道答案,但任何帮助将不胜感激。

最佳答案

似乎有一些未记录的更改。您需要将 $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
});

关于php - 新流明5.5项目 'Undefined variable: app',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46124133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com