Search code examples
laravellaravel-livewire

Laravel livewire binding checkboxes from array of object


How to bind an array of objects to checkboxes in Laravel Livewire:

The array looks like this:

[{"name":"A","selected":true}, {"name":"B","selected":true}]

My view blade:

@foreach($list as $index => $d)

   <input type="checkbox" wire:model="list.{{$index}}.selected" @if($d->selected) checked @endif>

@endforeach

The problem is when the checkbox is selected on unselected the array is not updated, how to solve this?


Solution

  • Get answer from the GitHub discussion need to use wire.model.live instead of wire.model.