I want to dynamically refresh the count badge on a custom page / relationship. I want this to happen when I add or delete items.
On both my add and delete actions I dispatch an event:
->after(static function (Component $livewire): void { $livewire->dispatch('refreshImages');})
->after(static function (Component $livewire): void { $livewire->dispatch('refreshImages');})
And then I use the
On
On
attribute to listen to this.
#[On('refreshImages')]public static function getNavigationBadge(): ?string{ // The count is NOT updated. return Livewire::current()->getRecord()->getAttribute('images_count') ?? null;}
#[On('refreshImages')]public static function getNavigationBadge(): ?string{ // The count is NOT updated. return Livewire::current()->getRecord()->getAttribute('images_count') ?? null;}
Although this behaviour works elsewhere, to refresh the list, it doesn't update the count.
#[On('refreshImages')]public function refresh(): void{ // Refresh the list. This works!}
#[On('refreshImages')]public function refresh(): void{ // Refresh the list. This works!}