简体   繁体   中英

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. This was working this earlier and I don't think I have changed anything.

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

The specific ContractorController method:

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. 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:

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 .

The skills URI segment is not one of them. You will need to add a separate route for that:

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

However, this isn't really RESTful design. You may be better off with a separate skills resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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