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

forrestedw's avatar

Livewire forgetting an array value when the model updates.

I have a blade loop in a Livewire component that looks like this:

@foreach($variants as $key => $variant)
    <div class="inline-flex justify-between w-full mb-2">
        <input wire:model.debounce.lazy="variants.{{ $key }}.name">
        <input wire:model.debounce.lazy="variants.{{ $key }}.values">
    </div>
@endforeach

When I update a value on the array, it forget the previous updates.

For examples, if I change the value of variants.1.name from foo, the value when the component was mounted, to bar then for that moment $this->variants[1]['name'] === bar is true.

However, if I then change the input value of eg variants.0.name to baz, then $this->variants[1]['name'] goes back to the value of foo, the value it had when the component was mounted.

How do I get the array to hold all the changes that are passed back from the browser, not just he most recent?

Yes, the properties are public

0 likes
7 replies
CorvS's avatar

@forrestedw Not sure if it has something to do with it, but try using wire:model.lazy (without debounce). How do you check if the values have changed or not? I just tried a minimum example and it seems fine.

forrestedw's avatar

I've removed the debounce at your suggestion and still get the same behaviour.

This is how I'm checking the values:

    public function updatedVariants()
    {
        dd($this->variants);
    }

Funny that it should work for you.

One piece of information that I didn't give is that all the functions etc are in a trait. I don't know how that would affected it but mentioning it in case it does.

CorvS's avatar
CorvS
Best Answer
Level 27

@forrestedw Indeed, when using updated I've got the same behaviour, but when I add a button with some action wire:click="test" and dump($this->variants); in there it works as expected. Do you have to use updated in order to achieve what you want?

1 like
forrestedw's avatar

Huh. Well would you look at that. That's only 5 hours I've been debugging that. Thank you for spotting that! Is this a bug? Should I open an issue on the repo do you feel?

CorvS's avatar

@forrestedw Don't know if it's a bug or not, maybe the changes are aggregated before they get "persisted". Doesn't hurt to open an issue I would say. Keep me posted please.

forrestedw's avatar

I was just opening an issue and created quick simple test with this in the class:

    public array $arrays;

    public function mount()
    {
        $this->arrays = [
            ['name' => 'foo'],
            ['name' => 'bar'],
        ];
    }

    public function updatedArrays()
    {
        dump($this->arrays);
    }

    public function test()
    {
        dump($this->arrays);
    }

and this in the view:

<div>
    @foreach($arrays as $key => $array)
        <input wire:model.lazy="arrays.{{$key}}.name" >
    @endforeach
    <a wire:click="test">test</a>
</div>

And now even test() doesn't work. :shrug:

Am I missing something, again?

CorvS's avatar

@forrestedw Hey, please use the @ sign in order to notify me next time. I just did another test. It seems like dd and dump print the array before it's updated. Try using Log for example and it works in both cases.

Log::info('Array = ', $this->arrays);
1 like

Please or to participate in this conversation.