laravel livewire actions not calling method when having more than one livewire action in compoent's view

4.8k views Asked by At

I have two livewire wire:click action in component's view. The first action does work fine but second doesn't.

<button wire:click="test">Test</button>
<button wire:click="add">Add</button>

Component class look like this:

public function test() {
  dd("test");
}
public function add() {
  dd("add");
}

So when i click on test button it shows test string but add button doesn't show add string. But if i remove/comment test button, second button will work fine. Why is that So?

1

There are 1 answers

2
Dan Harrin On

I expect that you have forgotten to wrap both buttons in a parent element in your view:

<div>
    <button wire:click="test">Test</button>
    <button wire:click="add">Add</button>
</div>