Search code examples
javascriptphplaravellaravel-7laravel-livewire

wire:click call two methods at once


I have a problem with wire:click event and I want to know, how to call two methods on one click. I have been tried several times without success, and I didn't found any information in the documentation so my examples:

in this case return method setItem is not defined, but the method is defined in the Livewire Component

wire:click="$emitTo('assign-modal', 'show-assign-modal'); setItem({{$book->id}})"

second case: in this case it's normal for me to not work, but I decided to give a chance and try what will happen

wire:click="$emitTo('assign-modal', 'show-assign-modal')" wire:click="setItem({{$book->id}})"

third case: in this case I have been tried to call the method with custom event, but still without success

wire:click="$emitTo('assign-modal', 'show-assign-modal'); $emitSelf('setData', {{$book->id}})"

Also I have an another idea, to pass the data to the first custom event assing-modal and after that to return the data to the parent component, but I think this idea is awful, so any help will be appreacited.


Solution

  • you cannot call 2 function in wire:click

    so in this case you should do like this

    wire:click="setItem({{$book->id}})"
    

    in component

    public function setItem($bookId)
    {
        $emitTo('assign-modal', 'show-assign-modal'); 
    }