Laravel 5条路线(耦合非必需参数)

Laravel 5条路线(耦合非必需参数),laravel,controller,routes,Laravel,Controller,Routes,当操作有两个非必需的参数时,我需要创建功能 因此,可以这样称呼行动: site/man/process/age/30/weight/80, site/man/process/age/30, site/man/process/weight/80, site/man/process/ Route::get('man/process/age/{age?}/weight/{weight?}', 'ManController@process'); 我尝试使用如下路线: site/man/pro

当操作有两个非必需的参数时,我需要创建功能

因此,可以这样称呼行动:

site/man/process/age/30/weight/80, 

site/man/process/age/30,

site/man/process/weight/80,

site/man/process/
Route::get('man/process/age/{age?}/weight/{weight?}', 'ManController@process');
我尝试使用如下路线:

site/man/process/age/30/weight/80, 

site/man/process/age/30,

site/man/process/weight/80,

site/man/process/
Route::get('man/process/age/{age?}/weight/{weight?}', 'ManController@process');
但是没有成功。有人知道如何正确地做到这一点吗


感谢您的帮助和建议。

我将采用完全不同的方法通过路由参数传递这些变量

考虑在请求正文中发送一个包含年龄和体重的POST请求,然后使用$request->all()在控制器中访问这些值

用示例编辑:

Route::post('man/process','ManController@process');

然后在controller process()方法中:


您可以使用
GET
request,并将参数作为查询字符串传递

Route::get('man/process', 'ManController@process');
URL : /man/process?age=10&weight=20
或者使用
POST
请求并传递您想要接收的内容:

public function getData(Request $request)
{
  // Data in this case would contain age and weight
  $data = $request->all();
}

我认为应该将参数设置为查询字符串,而不是类似的东西。所以你会有类似于<代码>/man/process?年龄=10,体重=20
我认为你应该研究多条路线。最高的是您当前拥有的路线。我甚至会使用
GET
请求,例如
man/process?年龄=31,体重=80