F
Filament6mo ago
Euu83

After applying a filter, I want to make a grouping to the resulting query but it does not do it.

groupByCurrency() is the second scope where I do the second grouping. When analyzing the resulting query it shows the where but not the grouping.
->filters([
Tables\Filters\Filter::make('month_year')
->form([
Forms\Components\Select::make('month')
->options([
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
])
->required()
->default(date('m')),
Forms\Components\Select::make('year')
->options($yearOptions)
->required()
->default(date('Y')),
])
->query(function ($query, array $data) {
if (isset($data['month']) && isset($data['year'])) {
$startDate = Carbon::create($data['year'], $data['month'], 1)->startOfMonth();
$endDate = Carbon::create($data['year'], $data['month'], 1)->endOfMonth();
$startDate = '2024-01-01';
$endDate = '2024-01-02';
$query->whereBetween('games_wagers_rolls.date',[$startDate,$endDate])->groupByCurrency();
}
})
])
->filters([
Tables\Filters\Filter::make('month_year')
->form([
Forms\Components\Select::make('month')
->options([
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
])
->required()
->default(date('m')),
Forms\Components\Select::make('year')
->options($yearOptions)
->required()
->default(date('Y')),
])
->query(function ($query, array $data) {
if (isset($data['month']) && isset($data['year'])) {
$startDate = Carbon::create($data['year'], $data['month'], 1)->startOfMonth();
$endDate = Carbon::create($data['year'], $data['month'], 1)->endOfMonth();
$startDate = '2024-01-01';
$endDate = '2024-01-02';
$query->whereBetween('games_wagers_rolls.date',[$startDate,$endDate])->groupByCurrency();
}
})
])
Solution:
I have been able to solve it by using the getTableQuery() method from the page/index
`protected function getTableQuery(): Builder { $query = GamesWagersRoll::query()->getRTP(); if(isset($this->tableFilters['month_year'])) {...
Jump to solution
1 Reply
Solution
Euu83
Euu836mo ago
I have been able to solve it by using the getTableQuery() method from the page/index
protected function getTableQuery(): Builder { $query = GamesWagersRoll::query()->getRTP(); if(isset($this->tableFilters['month_year'])) { $data = $this->tableFilters['month_year']; $startDate = Carbon::create($data['year'], $data['month'], 1)->startOfMonth(); $endDate = Carbon::create($data['year'], $data['month'], 1)->endOfMonth(); $query->whereBetween('games_wagers_rolls.date',[$startDate,$endDate]); $subquery = $query->whereBetween('games_wagers_rolls.date', [$startDate, $endDate]); $query = GamesWagersRoll::fromSub($subquery,'sub_orders') ->selectRaw('sub_orders.id,SUM(players) as players') ->groupBy('sub_orders.id') ->orderBy('sub_orders.id'); } return $query; }
Want results from more Discord servers?
Add your server