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.
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'])) { $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; }