dqp99585 2016-05-09 02:10
浏览 100
已采纳

Laravel RESTful控制器添加参数来创建

I am trying to use Laravel 5.2's RESTful resource controllers. However, when moving from my index to create, I would like to pass a parameter as the create page should be partially filled in.

edit The form that will be 'created' will have populated fields from the database already. So the create should take the id from the user that is clicked in the index.

My temporary solution:

Route::get('consultation/{id}', 'ConsultationController@create');
Route::resource('consultation', 'ConsultationController', ['except' => ['create']]);

Is there a way to add this to an options array in the same line as resource?

Thanks

Edit: I suppose in this case, my store would also need the same {id} parameter.

  • 写回答

1条回答 默认 最新

  • doskmc7870 2016-05-09 02:39
    关注

    I was also curious about that but I think that the Laravel Documentation is pretty clear about this:

    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

    And they add the following, meaning for me that if you want to override a defined route, you just need to put the definition on top of the Route::resource() definition.

    otherwise, the routes defined by the resource method may unintentionally take precedence over your supplemental routes

    EDIT

    After better understanding the question, I would let the restful controller as is, and create a new route like /user/{user-id}/consultations/create that is much more "restful" like.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)