laravel use $app inside routes error Undefined variable: app

自古美人都是妖i 提交于 2019-12-11 01:42:06

问题


laravel 5.2 documentation has used $app->get(..) in routing section. i cant use $app inside routes , it throw below exception:

ErrorException in routes.php line 15:

Undefined variable: app

回答1:


There is no such global variable as $app in Laravel. You are probably referring to Lumen.

Laravel framework at www.laravel.com is different from Lumen framework at www.lumen.laravel.com

Lumen is 'slim down' version of Laravel

If you are trying to register a route in Laravel this will do.

Route::get('/', function () { return 'Hello World'; });

Want to use variable?Try

$router->get('/', function () { return 'Hello World'; });

If you are interested in accessing app, which is not used for routing, try

 $app = app();



回答2:


The documentation you've linked to is for Lumen, not Laravel. Lumen is different than Laravel, and actually uses a completely different router than Laravel, so the routing is setup a little differently.

Routing in Laravel uses the Route facade. For example:

Route::get('foo', function () {
    return 'Hello World';
});

You want to take a look at the Laravel Routing documentation.



来源:https://stackoverflow.com/questions/35619101/laravel-use-app-inside-routes-error-undefined-variable-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!