dimanche 14 février 2021

Saving single value which is checked in checkbox in laravel

I have a problem with checkbox. When I click the update button, it will change all the values of the column into 1 while I want only the checked one to become 1. Here is my form:

<form action="" method="POST" enctype="multipart/form-data">
        @csrf
<td><input type="checkbox" id="checked" name="checked[]" value=""></td>

Controller:

    $data = $request->input('checked');
    $items = ItemReservationItem::whereIn('restaurant_id', $restaurantIds)->get();
    for($i=0; $i < $items->count(); $i++){
         if(empty($data)) {
            $items[$i]->done_check = 0;
         }
         else {
            $items[$i]->done_check = 1;
         }
         $items[$i]->save();
    }

enter image description here

enter image description here

I only want the checked rows is 1, but it changes all the table into 1.




Aucun commentaire:

Enregistrer un commentaire