Preventing StatsOverviewWidget from refreshing after every table action
What I am trying to do:
I want to show a custom ContactStatsWidget (extending Filament\Widgets\StatsOverviewWidget) in my resource page footer alongside my main table. It should only query once when the page loads, not every time I run an action on the table (like adding a guest).
What I did:
Added my widget inside getFooterWidgets() of my resource.
The widget works, but every table action refreshes it and runs the query again.
I tried ->lazy(), caching the query, etc., but it still refreshes on every action.
My issue/the error:
How can I prevent StatsOverviewWidget from re-running its query every time an action refreshes the page? Ideally, it should only load once (or only refresh when I explicitly tell it to).
Code:
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Card;
class ContactStatsWidget extends BaseWidget
{
protected function getCards(): array
{
return [
Card::make('Total Contacts', Contact::count()),
Card::make('Event Contacts', ContactEvent::count()),
];
}
}
And inside my resource:
public static function getFooterWidgets(): array
{
return [
ContactStatsWidget::class,
];
}
1 Reply