Home > Mobile >  How to get parameter of array in url path in get method in laravel API
How to get parameter of array in url path in get method in laravel API

Time:11-12

If url is "http://example.com/api/test?p=1&p=2" and method is "GET", I want to get [1,2] when I trying to call $request->p or $request->query("p").

But now, if url is same, I'll get "2" when I call $request->p.

How to do it?

CodePudding user response:

A parameter can only hold one value. In ?p=1&p=2 the second p=... sets the value for the parameter, overwriting the first one. If you want two values your parameter should be an array like this:

?p[]=1&p[]=2
  • Related