传递 HTTP 请求参数的多个值

Pass multiple values of a HTTP request parameter

如何传递单个 HTTP 请求参数的多个值,并在控制器中检索它们?

是否是这样的重复参数:

http://example.com/users?q=1&q=2

或像这样的连续多个值:

http://example.com/users?q=1,2

感谢您的帮助。

您可以像这样将数组传递给请求:

http://example.com/users?q[]=1&q[]=2

[]会将参数作为数组传递。因此,当您从请求中检索 q 时:

dd(request('q'));

它将为您提供以下内容:

array:2 [▼
  0 => "1"
  1 => "2"
]

就像你传递一个 html 数组值的输入一样, 你可以用 [] 传递它。例如/users?q[]=1&q[]=2

Route::get('users', function (Illuminate\Http\Request $request) {
    // when you dump the q parameter, you'll get:
    dd($request->q);
    // q = [1, 2]
});