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

LansoirThemos's avatar

Laravel Livewire checkbox show "Attempt to read property "..." on array"

i dont seem to find the question that match my case so i'm just gonna make one.

My problem is when i make an index page show all record of the DataBase with checkbox, the moment i click the checkbox, it shows an erorr like this "Attempt to read property "id" on array"

My component is like this:

class ProductCheckbox extends Component { public $data; public $selectedProduct = [];

public function render()
{    
    return view('livewire.product-checkbox');
}

} And my view is like this:

Name
<tbody>
    @foreach ($data as $product)
        <tr> 
            <td>
                <input type="checkbox" value="{{ $product->id }}" wire:model="selectedProduct">
            </td>

            <td> {{ $product->name }} </td>
    @endforeach
</tbody>
Although https://www.developerbook.net/ when i check $selectedProduct, there is already value in it when i click the checkbox, but it still show the error box "Attempt to read property "id" on array", and it point the error right at the "
0 likes
3 replies
migsAV's avatar

@lansoirthemos the problem could be your public $data.

You setting $data as a variable but no data, what data are you pulling?

migsAV's avatar

Are you using a Controller or another Livewire Component to pass data into your $data variable?

MohamedTammam's avatar

Change your wire:model to be

<tbody>
    @foreach ($data as $key => $product)
        <tr> 
            <td>
                <input type="checkbox" value="{{ $product->id }}" wire:model="selectedProduct.{{ $key }}">
            </td>

            <td> {{ $product->name }} </td>
    @endforeach
</tbody>

Please or to participate in this conversation.