mardi 7 novembre 2017

Update multiple checbox Laravel

I have a table association

ID_USER_CAR | USER_ID | CAR_ID | DELETED_AT

1               2         3        
2               2         5
3               2         10

The problem is on update... because the next time when i'm editing ...the user 2 will want only the car 3 and another car from list...for example car 7.

 @foreach($cars as $car)
     <label style="display:block" class="custom-control custom-checkbox">
      <input @if(in_array($car->car_id, $userCars)) checked @endif type="checkbox" name="cars[]" value="" class="custom-control-input"><span class="custom-control-indicator"></span><span class="custom-control-description"></span>
     </label>
  @endforeach

so after the update..the table will look something like this

 ID_USER_CAR | USER_ID | CAR_ID | DELETED_AT

    1               2         3        
    2               2         5    2017-10-15
    3               2         10   2017-10-15
    4               2         7




Aucun commentaire:

Enregistrer un commentaire