widget doesin't update when i use the filter on a table help please
<?php
namespace App\Filament\Resources\OrderResource\Widgets;
use App\Enums\OrderStatus;
use App\Filament\Resources\OrderResource;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class OrderStats extends BaseWidget
{
use InteractsWithPageTable;
protected function getStats(): array
{
$orders = OrderResource::getEloquentQuery();
$allOrdersCount = $orders->count();
$paidOrdersCount = OrderResource::getEloquentQuery()->where('status', OrderStatus::Paid->value)->count();
$holdOrdersCount = OrderResource::getEloquentQuery()->where('status', OrderStatus::Hold->value)->count();
return [
Stat::make('Orders', $allOrdersCount),
Stat::make('Paid Orders', $paidOrdersCount),
Stat::make('Hold Orders', $holdOrdersCount),
];
}
}
OrderResource::class
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;
public static function getWidgets(): array
{
return [
OrderStats::class,
];
}
public static function table(Table $table): Table
{
->filters([
DateRangeFilter::make('created_at')->label("Date")->defaultToday(),
],layout: FiltersLayout::AboveContent)
}
<?php
namespace App\Filament\Resources\OrderResource\Widgets;
use App\Enums\OrderStatus;
use App\Filament\Resources\OrderResource;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class OrderStats extends BaseWidget
{
use InteractsWithPageTable;
protected function getStats(): array
{
$orders = OrderResource::getEloquentQuery();
$allOrdersCount = $orders->count();
$paidOrdersCount = OrderResource::getEloquentQuery()->where('status', OrderStatus::Paid->value)->count();
$holdOrdersCount = OrderResource::getEloquentQuery()->where('status', OrderStatus::Hold->value)->count();
return [
Stat::make('Orders', $allOrdersCount),
Stat::make('Paid Orders', $paidOrdersCount),
Stat::make('Hold Orders', $holdOrdersCount),
];
}
}
OrderResource::class
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;
public static function getWidgets(): array
{
return [
OrderStats::class,
];
}
public static function table(Table $table): Table
{
->filters([
DateRangeFilter::make('created_at')->label("Date")->defaultToday(),
],layout: FiltersLayout::AboveContent)
}
2 Replies
Why should it? Those 2 are not related.
Have you completed the setup by reading the docs : https://filamentphp.com/docs/3.x/panels/resources/widgets#accessing-page-table-data-in-the-widget