I'm getting some input from a dynamically generated form (I'm using jQuery to allow the user to add fields) using Input::all(). The field names are 'first_names[]', 'last_names[]' and 'emails[]'.
The $input variable now looks like this:
array (size=4)
'_token' => string '3VCQFUmAx8BNbSrX9MqjGtQhYovOaqecRUQSAL2c' (length=40)
'first_names' =>
array (size=1)
0 => string 'John' (length=4),
1 => string 'Jane' (length=4)
'last_names' =>
array (size=1)
0 => string 'Doe' (length=3),
1 => string 'Doe' (length=3)
'emails' =>
array (size=1)
0 => string 'johndoe@example.com' (length=24),
0 => string 'janedoe@example.com' (length=24)
What I want to do is create an array from that input that looks like this:
array (
0 => array(
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com'
),
1 => array(
'first_name' => 'Jane',
'last_name' => 'Doe',
'email' => 'janendoe@example.com'
)
)
Is there a simple way to do this without iterating over each array and building new ones? Is there a better way to generate the input? Thanks.
OK guys, with the help of alexrussell in Laravel IRC we've figured it out.
First thing is the JS:
We create a delegateId variable which we append to the get request URL and then in our routes.php we do:
This sends the id to the view we use to generate the form fields. Then in the form we do:
Once we get the input for delegates using:
We then have a nice array to work with, that is exactly what we're after: