@snapey please help me with this.
Oct 25, 2024
3
Level 1
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;
}
Level 11
Try this https://codecourse.com/articles/how-to-refresh-and-re-render-a-livewire-component
Hopefully it will have an approach to the issue you are having.
Please or to participate in this conversation.