1

I want to know the best practices for passing array in url and how can i define my routes for accepting that array in laravel 5 and pass it to the controller. Any Suggestions??

Let us take an example

URL - http://localhost/new/public/api/getaudit/

In this url, I want to pass array. Like: array('car','bike') Thanks

9
  • 1
    Have you tried anything, yet? Commented Nov 20, 2015 at 14:17
  • 1
    @Steve: this array=car&array=bike will override one value with the other, so in $_GET['array']is just the value bike, you need array[]=car&array[]=bike Commented Nov 20, 2015 at 14:25
  • 2
    @swidmann oh yes, i forget that php does that (its a perfectly valid query string), amended: http://localhost/new/public/api/getaudit/?array[]=car&array[]=bike Commented Nov 20, 2015 at 14:28
  • 1
    In our project we solve exactly this problem (getting audit) with a POST and send an JSON-Array with IDs as body. It was our preferred solution instead of doing one get-Request per audit or using URL-params. Commented Nov 20, 2015 at 14:28
  • 1
    you could also jusy use comma seperated string and explode it yourself, to save a few chars: /?array=car,bike $array = explode(',', $_GET['array']; Commented Nov 20, 2015 at 14:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.