我正在尝试使用 Laravel 5.2 的 RESTful 资源 Controller 。但是,当从索引移动到创建时,我想传递一个参数,因为创建页面应该部分填充。
编辑 将“创建”的表单将已经填充数据库中的字段。因此,创建应该从索引中单击的用户获取 id。
我的临时解决方案:
Route::get('consultation/{id}', 'ConsultationController@create');
Route::resource('consultation', 'ConsultationController', ['except' => ['create']]);
有没有办法将其添加到与资源同一行的选项数组中?
谢谢
编辑:我想在这种情况下,我的商店也需要相同的 {id} 参数。
最佳答案
我也对此感到好奇,但我认为 Laravel 文档对此非常清楚:
If it becomes necessary to add additional routes to a resource controller beyond the default resource routes, you should define those routes before your call to Route::resource
他们添加了以下内容,对我来说这意味着如果你想覆盖定义的路由,你只需要把定义放在 Route::resource()
之上定义。
otherwise, the routes defined by the resource method may unintentionally take precedence over your supplemental routes
编辑
更好地理解问题后,我会让restful Controller 保持原样,并创建一条新路线,如 /user/{user-id}/consultations/create
这更像是“安静”的事情。
关于php - Laravel RESTful Controller 添加参数创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37106889/