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

NicolasJ's avatar

Data Binding of item in array

Hello,

I wonder how to achieve this.

In the blade livewire component there is an iteration over items for which there is binding, for example :

@foreach ($items as $item)
   <x-input wire:model="data.{{ $item->id }}" type="text" />
@endforeach

And in the livewire component the public property $data

Thus, in the component you can retrieve the informations in the array $data.

But what I try to do is that foreach item of $data I would like to add completion. For example, when the user start to write in an input there is a result depending on the content write by the user.

The problem is : how to achieve independently each item of the array as it is the total array that is bind ?

Of course the number of item in data is not always the same.

Hope to be clear enough.

There is no information on this page : https://laravel-livewire.com/docs/2.x/properties#binding-models

If someone have any suggestions ?

0 likes
3 replies
Nakov's avatar

@nicolasj what I do in one of my projects, I have a multidimensional array, so for example you can add another field:

@foreach ($items as $item)
   <x-input wire:model="data.{{ $item->id }}.name" type="text" />
   <x-input wire:model="data.{{ $item->id }}.completed" type="checkbox" />
@endforeach

then the resulting data will be:

$data = [
   1 => ['name' => 'Name', 'completed' => 0],
   2 => ['name' => 'Name 2', 'completed' => 1],
];

try it out and let me know if that will work for you

4 likes
NicolasJ's avatar

In fact, I was looking for which input is filling and not the entire array

I posted a response below in same time you write ;)

Thanks for reply

NicolasJ's avatar

Okay It could be managed with :

    public function updating($name, $value)
    {
    }

That provide in the name the index of the array ;)

That's it ! Hope it helps

1 like

Please or to participate in this conversation.