I'm trying to figure if i could emit an event from a Laravel regular controller and define a listener on a Livewire component. There's my journey so far:
I've generated the event:
php artisan make:event NewOrder
then, on the Controller method placeNewOrder
i'm triggering the event like this:
event(new NewOrder())
On the Livewire component i define a varible $showNewOrderNotification
and the listener:
public $showNewOrderNotification = false
protected $listeners = ['NewOrder' => 'notifyNewOrder'];
and setting the method notifyNewOrder
public function notifyNewOrder()
{
$this->showNewOrderNotification = true;
}
the livewire view is only showing an alert when the $showNewOrderNotification
variable is true:
@if($showNewOrderNotification)
<div class="alert alert-danger text-uppercase">
New Orders !!!
</div>
@endif
This should be pretty straight forward but for some reason the listener is not getting the event.
I appreciate all the help.