问题
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