In the function "add" at some point it throws and event to the component "shopping-cart". In the "shopping-cart" component, i want to refresh the component manually when it receives the event. On the livewire site it only shows how to do it on the component view, by clicking a button and livewire handles the rest, but those function seems to not be available in the backend. Is the anyway around this or am i missing something??
//
// on the shopping-cart component
#[On('basketUpdated')]
public function basketUpdated(): void
{
// something here
}
// Adding more products to the Basket;
public function add($value): true|LaravelNotify
{
// Attempt to add the product to the use Basket DB
$addProductToBasket = $this->includeInBasket($value);
// checking for error
if (!$addProductToBasket)
return notify()->error('you are not connected, please connect and try again!', 'Could not update basket');
// Event to refresh shopping cart component
$this->dispatch('basketUpdated')->to('shopping-cart');
return true;
}
2
Answers
Instead of using the On attribute, you can make a
protected $listeners
array and refresh when the event is triggered.Update you blade with,