luisferfranco's avatar

Buttons stop working after deleting a model

I'm just starting using Livewire 3, I have done this many times in Livewire 2 and works, so this puzzles me.

Loginc in my component is quite easy: send the paginated User to the blade:

public function render()
{
  return view('livewire.user.index', [
    'users' => \App\Models\User::where('name', 'like', "%$this->search%")
      ->paginate(10),
  ]);
}

Then in the view, inside the foreach I have something as simple as:

@foreach ($users as $user)
  <button wire:click="destroy({{ $user->id }})">Destroy {{ $user->name }}</button>
@endforeach

The destroy method is as simple as:

public function destroy(\App\Models\User $user) {
  $user->delete();
}

So, problem here is, when I click the button the first time, it actually deletes the model, I can check it in the database, it also removes the button, but the following cllicks in the other buttons does nothing. If I inspect the view, of course I get the wire.click=destroy(28) or whatever id

I thought it had something to do with the pagination, so I took it out, and the problem persists.

Is there something new in Livewire 3? I'm not using Livewire components, so I think I don't have to use the :key property... or do I?

0 likes
2 replies
luisferfranco's avatar

@tykus Ughhhh... it's wire:key I was using :key I don't know why I recalled it wrong. Thanks a lot! I'm feeling like an idiot... again.

Please or to participate in this conversation.