I would probably give each checkbox a unique name and have value =1
<input type="checkbox" name="checked[]{{ $p->id }}" value="1">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to get all the payments that is been selected through the checkboxes and then update the value in the database by '1' which means its paid. But when I try to get the values of checkbox array I only get 1 data in the array and not all selected. Any help?
View
@foreach($sellerID as $p)
<form action="/paid/{{$p->id}}" method="post" enctype="multipart/form-data">
@csrf
<td><input type="checkbox" name="checked[]" value="{{ $p->id }}"></td>
<td> {{$p->order_number}} </td>
<td>
<input id="commission" type="text" class="form-control" name="commission"
value="{{ $p->commission_value }}" readonly autocomplete="notes" style="width: 15%;" autofocus>
</td>
<td> {{$p->product_name}} </td>
<td>
@if($p->sellet_commission_paid == '0')
<button type="submit" class="btn btn-default" style="background-color:red">
<b><em>UNPAID</b></em>
</button>
@else
<a href="#" class="btn btn-default" style="background-color:green"><b><em>PAID</b></em></a>
@endif
<td>
</form>
@endforeach
Controller
$checked = $request->input('checked');
// $checkboxes = $request->checked;
dd($checked);
die();
// dd(che
this is the updated code as but now this is not taking all values and passing to the database to update. The code seems to be fine. Am I doing something wrong in the view file?
Controller
$commissionValue = Input::get('commission');
$checked = $request->input('checked');
foreach($checked as $c) {
$findPaymentId = Payment::where('id', '=', $c)->get();
// echo $findPaymentId->commission_value;
// die();
foreach($findPaymentId as $f) {
if($f->commission_value == $commissionValue) {
$updateStatus = Payment::where('id', $f->id)->update([
// 'status' => '1',
'sellet_commission_paid' => '1',
]);
} elseif($findPaymentId->agent_commission == $commissionValue) {
$updateStatus = Payment::where('id', $id)->update([
// 'status' => '1',
'agent_commission_paid' => '1',
]);
}
}
Session::flash("message", "You confirmed that you have received the commission.");
return redirect()->back();
}
View
@if(count($sellerID)>0)
<form action="/paid" method="post" enctype="multipart/form-data">
@foreach($sellerID as $p)
<tr>
@csrf
<td><input type="checkbox" name="checked[]" value="{{ $p->id }}"></td>
<td> {{ $p->order_number }} </td>
<td>
<input id="commission" type="text" class="form-control" name="commission"
value="{{ $p->commission_value }}" readonly autocomplete="notes" style="width: 15%;" autofocus>
</td>
<td> {{$p->product_name}} </td>
<td>
@if($p->sellet_commission_paid == '0')
<button type="submit" class="btn btn-default" style="background-color:red">
<b><em>UNPAID</b></em>
</button>
@else
<a href="#" class="btn btn-default" style="background-color:green"><b><em>PAID</b></em></a>
@endif
<td>
</tr>
@endforeach
</form>
</tbody>
@endif
Please or to participate in this conversation.