DEV Community

Discussion on: Peasy way to Show Alerts in Laravel Livewire

Collapse
 
wcaaan profile image
Wcan

how can i move $this->dispatchBrowserEvent function a static helper ? if i move $this->dispatchBrowserEvent to helper it says. "using this when not in object context" also self::dispatchBrowserEvent does not work, it only works if i use it directly in store function in livewire component

Collapse
 
abrardev99 profile image
Abrar Ahmad

You need to pass $this as parameter.
For example helper will looks like below

public function dispatch($content)
{
$content->dispatchBrowserEvent('success', ['message' => 'success']);
}

and then call in Livewire

dispatch($this);