I want to call my child component public method from the parent component
//parent.php
class Parent extends Component
{
public function render()
{
return view('livewire.parent');
}
}
//child.php
class Child extends Component
{
public function render()
{
return view('livewire.child');
}
public function childMethod()
{
// Done somethings here
}
}
Now when inside my parent blade view I try to call the child component method like following
//parent.blade.php
<button wire:click="childMethod"></button>
then I'm getting the error
Livewire: Unable to call component method. Public method [childMethod] not found on component: [parent]
In your child.php you need to place:
//child.php
protected $listeners = ['parentIsCalling' => 'childMethod'];
And in your blade view it should be:
//parent.blade.php
<button wire:click="$emit('parentIsCalling')"></button>
Because first of all your wire:click function without $emit function is only limited to the Scope of it's own Livewire instance.
And secondly your Parent Class is not listening or opening to receive input from any other LiveWire instance.