0

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?

2
  • 2
    Did you read the docs? These are laravel basics $request->query('p') will get the url parameter "p". You could have found that yourself... Commented Nov 12, 2021 at 7:08
  • 1
    @GertB. but $request->query('p') is also return "2", not [1,2] Commented Nov 12, 2021 at 7:16

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! that's what I want, and it work successfully.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.