在 laravel 5.2 中使用附加控制器进行路由时 RouteCollection 中的 NotFoundHttpException

NotFoundHttpException in RouteCollection when routing with additional controller in laravel 5.2

我收到这个错误-->'NotFoundHttpException in RouteCollection.php line 161'..当我尝试在 laravel 5.2 中调用我的附加控制器时..我已经 php artisan serve 激活 localhost:8000..你能在laravel中解释一下控制器路由的基本布局吗?

NotFoundHttpException 当没有给定的路由与您对某个 endpoint/url 的给定请求匹配时发生。

确保您将请求发送到正确的 url,它在您的 routes.php(web.php 代表 laravel 5.3+)中使用正确的动词正确定义, (获取、POST、补丁等)。

基本流程是这样的:

在您的 routes.php 中,您可以定义如下路线:

Route::get("/users", "UsersController@show");

然后在你的 Http 文件夹中定义给定的控制器,它是你在上面的调用中提到的名称,任何进行的 @ 符号都是一个自动调用的回调函数。

因此在您的 http/UsersController.php 中,您将拥有:

public function show(Request $request) {
    //Do something with your request.
    return "Something"; //could be an array or string or 
    //whatever since laravel automatically casts it into JSON,
    //but it's strongly recommended to use transformers and compact method.
}

有关更多信息,请尝试查看 laravel 文档,它们提供了一种令人惊叹的入门教程。 Laravel Docs