Summer Sale! All accounts are 50% off this week.

PRESTIGE2930's avatar

How to manually refresh in Livewire

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;
}
0 likes
3 replies
PRESTIGE2930's avatar

@jsanwo64 thanks, it wasnt working at first but with some touch up it finally did. I think it was having some hidden clashes with my mount function

1 like

Please or to participate in this conversation.