【发布时间】:2016-06-29 15:16:07
【问题描述】:
当您使用Route::resource('recipe', 'RecipeController'); 定义资源时,会定义以下路由:/photo/{photo}/edit,一旦您定义了所有资源,您将拥有如下内容:
/recipes/{recipes}/edit/allergens/{allergens}/edit/ingredients/{ingredients}/edit
因为我的所有记录都使用 id 作为主键 (MongoDB),所以我希望使用 {id},如下所示:
/recipes/{id}/edit/allergens/{id}/edit/ingredients/{id}/edit
我在Router 类中进行了挖掘,但我不知道如何指定它。
当我使用Form::model($record) 创建一个表单时,我会得到类似/recipes/{recipes} 这样的操作,因为recipes 是$record 的属性。
如何将key参数的名称定义为id而不是recipes、allergens、ingredients?
【问题讨论】:
-
那么您关心的是路由还是表单构建器?
-
我更关心路线,我希望它们遵循相同的模式。例如
{resource}/{id}/edit -
那就这样吧。但请记住嵌套资源 - 就像在答案中一样。