Check the link => https://laravel-livewire.com/docs/2.x/properties#binding-nested-data
The reason is you are binding to the same variable
<input wire:model="selected" <= here
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
whenever i check a box i always get 1 value at a time i want to get all the selected values, i making a ecommerce application and i want this checkboxes in shop page so user can filter out without the need of submit button
so instead of working like this :
0 => 1
1 => 2
2 => 3 //these are selected values , the more you select the more array values will be added
its working like this:
1 => 2 //only gets 1 value when checkbox is selected
how do i bind those selected values , i have been researching this about 3 days and i have still not figured it out
any help would be much much appreciated
blade view file:- shop-component livewire :
<div class="brand">
@foreach ($attributes as $attribute)
<h3 >{{$attribute->name}}</h3>
<hr class="hr_category">
@foreach ($attribute->attributeValues as $item)
<div class="category_sort_wrapper">
<input wire:model="selected" id="{{$loop->index}}" name="{{$loop->index}}" value="{{$item->id}}" type="checkbox"> <h6 class="category_sort">{{$item->value}}</h6>
</div>
@endforeach
@endforeach
</div>
logic file: ShopComponent
public array $selected = array();
public function mount()
{
$this->selected = AttributeValue::all()->pluck('id')->toArray();
}
function updatedselected()
{
// wants the checkbox selected values in $this->selected array
dd($this->selected);
}
@CODE-AXION You have been advised how to work with an array. If you can't initialise the checkboxes on mount then you will need to deal with the fact that the array will only tell you the checked checkboxes and the others wll need to assume to be false.
Please or to participate in this conversation.