我对Laravel很新,说实话 - 这是一个很棒的框架。但是,我对一些嵌套资源有点困惑 - 包括CRUD和它们。
对于我正在使用的路线
Route::resource('startups','StartupsController');
Route::resource('startups.usecases','UsecasesController');
php artisan route:list
| | GET|HEAD | admin/startups | admin.startups.index | App\Http\Controllers\StartupsController@index | web,admin,auth:admin |
| | POST | admin/startups | admin.startups.store | App\Http\Controllers\StartupsController@store | web,admin,auth:admin |
| | GET|HEAD | admin/startups/create | admin.startups.create | App\Http\Controllers\StartupsController@create | web,admin,auth:admin |
| | DELETE | admin/startups/{startup} | admin.startups.destroy | App\Http\Controllers\StartupsController@destroy | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup} | admin.startups.show | App\Http\Controllers\StartupsController@show | web,admin,auth:admin |
| | PUT|PATCH | admin/startups/{startup} | admin.startups.update | App\Http\Controllers\StartupsController@update | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/edit | admin.startups.edit | App\Http\Controllers\StartupsController@edit | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases | admin.startups.usecases.index | App\Http\Controllers\UsecasesController@index | web,admin,auth:admin |
| | POST | admin/startups/{startup}/usecases | admin.startups.usecases.store | App\Http\Controllers\UsecasesController@store | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/create | admin.startups.usecases.create | App\Http\Controllers\UsecasesController@create | web,admin,auth:admin |
| | DELETE | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.destroy | App\Http\Controllers\UsecasesController@destroy | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.show | App\Http\Controllers\UsecasesController@show | web,admin,auth:admin |
| | PUT|PATCH | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.update | App\Http\Controllers\UsecasesController@update | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/{usecase}/edit | admin.startups.usecases.edit | App\Http\Controllers\UsecasesController@edit | web,admin,auth:admin |
对于父母,这里称为"初创公司",一切都很好,我可以CRUD一切都很好。
对于孩子,这里称为" usecases",index,create和store都可以。当我尝试在模板中添加链接到编辑,删除或显示时,我开始得到:缺少[Route:admin.startups.usecases.destroy]所需的参数[URI:admin / startups / {startup} / usecases / {用例}]。
我的索引裁剪文件中的链接:
<li><a href="{{ route('admin.startups.usecases.show',$startup->id, $usecase->id) }}">Show</a></li>
返回该错误。
在我的UsecasesController中
public function show($startup_id, $usecase_id)
{
$startups = $startup_id;
$usecase = Usecase::find($usecase_id);
return view('admin.startups.usecases.show')
->with('usecase', $usecase)
->with('startups', $startups);
}
TLDR:我可以在父母和#34;初创公司&#34;上访问和CRUD一切。我可以为孩子创建和存储,但不能编辑,显示或删除 - 用于&#34; usecases&#34;。
感谢您的帮助。
答案 0 :(得分:3)
您需要将参数作为数组传递:
route('admin.startups.usecases.show', [$startup->id, $usecase->id])
show()
方法如下所示:
public function show($startup, $usecase)
{
....