Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading