Reputation: 55
I have the table with each row containing checkbox where checkbox value is set as id from the database. How can i access them to controller to update in database. I have tried to dump the value in my controller but it show NULL. Here is my view:
<form action= "po" method="POST" >
@csrf
<input type="submit" name="submit">
<div class="table-responsive">
<table class="table custom-table">
<thead>
<tr>
<th scope="col">
<label class="control control--checkbox">
<input type="checkbox" class="js-check-all"/>
<div class="control__indicator"></div>
</label>
</th>
<th scope="col" >S.N</th>
<th scope="col">LC NO</th>
<th scope="col">Applicant</th>
<th scope="col">Doc Value</th>
<th scope="col">Doc Received date</th>
<th scope="col">LC Type</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $number = 1;?>
@foreach($datas as $items)
<tr>
<th scope="row" style="padding:20px">
<label class="control control--checkbox">
<input type="checkbox" name="checkboxlist[]" value="{{$items->id}}" />
<div class="control__indicator"></div>
</label>
</th>
<td>{{$number}}</td>
<td>{{$items->lc_no}}</td>
<td>{{$items->applicant}}</td>
<td>{{$items->doc_value}}</td>
<td>{{$items->rec_date}}</td>
<td>{{$items->sight_usance}}</td>
</tr>
<?php $number++; ?>
@endforeach
</tbody>
</table>
</div>
</form>
Here is my Controller
function po(Request $req){
dd($req->chekboxlist);
}
Upvotes: 0
Views: 971
Reputation: 15319
You are accessing wrong key from Request $req->chekboxlist
But it should be
$req->checkboxlist
Always add Validation to Avoid erorrs while saving data
$validate=Validator::make($request->all(), [
"checkboxlist" => "required|array",
]);
if($validate->fails()){
return redirect()->back()->with("errors",$validate->errors());
}
Upvotes: 1