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
Dennis Koch
Dennis Koch7mo ago
Why should it? Those 2 are not related.
Want results from more Discord servers?
Add your server