简体   繁体   English

Laravel资源路由NotFoundHttpException

[英]Laravel Resource route NotFoundHttpException

I am using the resource route to access several crud functions on my site but I am getting a NotFoundHttpException error when accessing one of several pages. 我正在使用资源路由来访问网站上的多个Crud函数,但是访问多个页面之一时却收到NotFoundHttpException错误。 This was working this earlier and I don't think I have changed anything. 这在较早的时候就起作用了,我认为我没有做任何改变。

Route::resource('/contractors', 'ContractorController');

The specific ContractorController method: 具体的ContractorController方法:

public function skills($id)
{
    $contractor = Contractor::find($id);
    return View::make('contractors.skills')
        ->with('contractor', $contractor);
}

I have all of the basic crud methods located in the ContractorController too. 我也有所有位于ContractorController中的基本Crud方法。 I am using the skills method to create a new view that edits tags in a pivot table 我正在使用技能方法来创建一个新视图以编辑数据透视表中的标签

my url is public/contractors/1/skills and this blade view: 我的网址是public / contractors / 1 / skills和以下刀片视图:

contractors/skills.blade.php 

Do you see anything that I am doing wrong? 您看到我做错了什么吗?

There's only a few routes that Resource controllers by default will handle, you can see a full list of them (7 in all) in the documentation entry for Resource Controllers . 默认情况下,Resource controllers仅处理少数几条路由,您可以在Resource Controllers的文档条目中看到它们的完整列表(共7条)。

The skills URI segment is not one of them. skills URI段不是其中之一。 You will need to add a separate route for that: 您将需要为此添加一条单独的路线:

Route::get('/contractors/{contractorId}/skills', 'ContractorController@skills');

However, this isn't really RESTful design. 但是,这并不是真正的RESTful设计。 You may be better off with a separate skills resource. 使用单独的skills资源可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM