I've done a ton of looking through older posts and no luck yet, I'm trying to update multiple rows within a table from a single form with the ID being the primary key.
The contents are being displayed in what looks like a spreadsheet where the user can edit multiple rows.
I'm getting an undefined index: ID error.
The code I'm using bellow seems really close though something isn't right.
If anyones done this before and can correct this code your help would be greatly appreciated!
Thank you.
protected function updateMultiple(Request $request)
{
$data = $request->except(['_token']);
// dd($data);
for($i = 0; $i <= count($data['id']); $i++) {
$input = [
'id' => $data['id'][$i],
'Channel' => $data['Channel'][$i],
'Posts' => $data['Posts'][$i],
'Monthly_Admin_Fee' => $data['Monthly_Admin_Fee'][$i],
'Legal_Fee' => $data['Legal_Fee'][$i],
'Valuation_Fee' => $data['Valuation_Fee'][$i],
'Mortgage_Risk_Fee' => $data['Mortgage_Risk_Fee'][$i],
];
DB::table('membership')->update($input);
}
}
View
@foreach($members as $member)
<tr>
<td class="text-right">
<input type="text" style="padding-right: 8px;padding-left: 8px;" name="id[]" id="id">{{$member->id}}</td>
<td><input type="text" id="Channel" name="Channel[]" class="form-control" value="{{$member->Channel}}"></td>
<td><input type="text" id="Posts" name="Posts[]" class="form-control" value="{{$member->Posts}}"></td>
<td><input type="text" id="Monthly_Admin_Fee" name="Monthly_Admin_Fee[]" class="form-control" value="{{$member->Monthly_Admin_Fee}}"></td>
<td><input type="text" id="Legal_Fee" name="Legal_Fee[]" class="form-control" value="{{$member->Legal_Fee}}"></td>
<td><input type="text" id="Valuation_Fee" name="Valuation_Fee[]" class="form-control" value="{{$member->Valuation_Fee}}"></td>
<td><input type="text" id="Mortgage_Risk_Fee" name="Mortgage_Risk_Fee[]" class="form-control" value="{{$member->Mortgage_Risk_Fee}}"></td>
</tr>
@endforeach
$dataafter this line$data = $request->except(['_token']);array:8 [▼ "id" => array:10 [▶] "Channel" => array:10 [▶] "Posts" => array:10 [▶] "Monthly_Admin_Fee" => array:10 [▶] "Legal_Fee" => array:10 [▶] "Valuation_Fee" => array:10 [▶] "Rate" => array:10 [▶] "Mortgage_Risk_Fee" => array:10 [▶] ]