lumen framework routing not working

萝らか妹 提交于 2019-11-30 12:32:17

You have to use the fully qualified classname:

$app->get('/', 'App\Http\Controllers\HomeController@index');

OR wrap all routes in a group (which is actually how it's done under the hood in Laravel 5)

$app->group(['namespace' => 'App\Http\Controllers'], function($group){

    $group->get('/', 'HomeController@index');
    $group->get('foo', 'FooController@index');

});

It appears to be undocumented right now, but you need to use the full namespace path to the controller.

So your route would look like this:

$app->get('/', 'App\Http\Controllers\HomeController@index');

The difference lies in the RouteServiceProvider that ships with Laravel, which can be found in app/Providers/RouteServiceProvider.php, check out the map method, it looks as follows

$router->group(['namespace' => $this->namespace], function($router)
{
    require app_path('Http/routes.php');
});

So all of your application routes are actually grouped under a default namespace, which is usually App\Http\Controllers.

Hope that helps!

Take a look at the file /bootstrap/app.php There you can make some settings. Also there, at the bottom of the file, you will find the following lines.

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../app/Http/routes.php';
});

return $app;

Which should serve your calls with the right namespace.

Also you can activate the .env settings right there :)

Take a look at this Post https://mattstauffer.co/blog/introducing-lumen-from-laravel

Hope this helps someone! :)

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