[英]laravel routing / How i can use array of parameters in route
I want to use this route我想使用这条路线
Route::get('/myapi/params/{param11},{param2}/producers/{producer1},{producer2}', 'MyApiController@index'); Route::get('/myapi/params/{param11},{param2}/producers/{producer1},{producer2}', 'MyApiController@index');
I try to use different params and producers values in route.我尝试在路由中使用不同的参数和生产者值。 And it's may be 1,2,3 or more values for params
它可能是 1,2,3 或更多的参数值
Can I use it's in laravel?我可以在 laravel 中使用它吗?
You should merge them into a single parameter您应该将它们合并为一个参数
Route::get(
'/myapi/params/{params}/producers/{producers}', 'MyApiController@index'
);
And in a controller method for example:并以 controller 方法为例:
use Illuminate\Http\Request;
public function checkParams(Request $request)
{
$route = $request->route();
$params = explode(',', $route->param('params'));
$producers = explode(',', $route->param('producers'));
}
Therefore you get an ordered array with all your params/producers, whatever how many.因此,无论有多少,您都会得到一个包含所有参数/生产者的有序数组。
You can't used ,
inside route.你不能使用
,
内部路线。 So You can use route like所以你可以使用类似的路线
Route::get('/myapi/params/{param11}/{param2}/producers/{producer1}/{producer2}', 'MyApiController@index');
It will work for you.它会为你工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.