php - Laravel RESTful Controller 添加参数创建

标签 php laravel model-view-controller controller

我正在尝试使用 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/

相关文章:

javascript - Laravel 4 中的 JQuery 没有返回数据..为什么?

php - 在 Laravel 中获取插入行的 ID

php - Laravel 迁移 : unique key is too long, 即使指定

java - MVC在哪里保留对 Controller 的引用?

php - 使用存储在 mysql 文本中的变量

php - Nginx 快速 CGI 缓存打开 error_page 404

javascript - 使用 php 不使用 jQuery 进行 Ajax 表单验证

php - 如何在数据库中存储无限标签?

c# - 使用枚举和 Entity Framework 脚手架从模型创建下拉列表?

javascript - 无法让简单的 agility.js 工作