Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cipherdenny's avatar

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 or unselected the array is not updated, how to solve this?

0 likes
3 replies
sevenTopo's avatar

Did u tried something like this ? are u using alpinejs or javascript ?

<input type="checkbox" wire:model="list.{{$index}}.selected"  @if(!empty($list[$index]['selected']) && $list[$index]['selected'] == true  ) checked  @endif>
cipherdenny's avatar

@sevenTopo Hi, thanks for answering my question, yes I have use check for checked and unchecked using if. I've updated my questions.

cipherdenny's avatar
cipherdenny
OP
Best Answer
Level 1

Get answer from Livewire maintainer on github discussion need to use wire.model.live instead of wire.model.

Please or to participate in this conversation.