I have a form which takes the following structure
<tr id='actionRow'>
<td>
<input type="text" name='actionInput[0][]' id="actionInput" placeholder='Action' class="form-control"/>
</td>
<td>
<select class="responsibility" name="actionInput[1][]" id="responsibilityInput">
<option value=""></option>
@foreach($users as $user)
<option value="{{ $user->userName }}">{{ $user->userName }}</option>
@endforeach
</select>
</td>
<td>
<input type="text" name='actionInput[2][]' id="dateInput" placeholder='Completion Date' class="form-control dateControl"/>
</td>
</tr>
I have an option for the user to add rows to this form, and it basically clones the table row. The end result I get in my controller when I output actionInput is something like the following
array:3 [▼
0 => array:3 [▼
0 => "Action Input 1"
1 => "Action Input 2"
2 => "Action Input 3"
]
1 => array:3 [▼
0 => "Responsibility Input 1"
1 => "Responsibility Input 2"
2 => "Responsibility Input 3"
]
2 => array:3 [▼
0 => "Date Input 1"
1 => "Date Input 2"
2 => "Date Input 3"
]
]
When this data is added to my database table, a table row should consist of one bit of data from each array. So if I take the above data and insert it into a database, my table rows should look like the following
Action | Responsibility | Date
-------------------------------------
Input 1 | Responsibility 1 | Date 1
-------------------------------------
Input 2 | Responsibility 2 | Date 2
-------------------------------------
Input 3 | Responsibility 3 | Date 3
-------------------------------------
In my controller I am currently doing this
$actions = Input::get('actionInput');
foreach($actions as $action => $category) {
$contactReportActions = new ContactReportActionsDoc();
$contactReportActions->contactReportId = $contactReport->id;
foreach($category as $key => $value){
$contactReportActions->action = $value;
$contactReportActions->responsibility = $value;
$contactReportActions->deliveryDate = $value;
}
$contactReportActions->save();
}
The problem is, that produces something like the following
Action | Responsibility | Date
----------------------------------------------------------
Input 1 | Input 2 | Input 3
----------------------------------------------------------
Responsibility 1 | Responsibility 2 | Responsibility 3
----------------------------------------------------------
Date 1 | Date 2 | Date 3
----------------------------------------------------------
So how could I correct this within my controller so it inputs the data to my database correctly?
Thanks