© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
3 replies
gladjanus43

group table rows by morph column

Hi, i have a price lines table with a parent morph table. A price line can be added to a Order or TransportOrder.
I would like to group the table by the unique combination of parent_type and parent_id but i can't get it to work...

I have tried modifying query and then calling the default group on the column with parent_unique:
->modifyQueryUsing(function (Builder $query) {
  return $query->selectRaw('*, CONCAT(parent_type, " ", parent_id) as parent_unique');
})
->modifyQueryUsing(function (Builder $query) {
  return $query->selectRaw('*, CONCAT(parent_type, " ", parent_id) as parent_unique');
})


I tried adding an attribute to the PriceLine model but i think the group by is executed as an sql query so the attribute does not work. It does load in the table of course but i cant group on it...

Also tried making a group column via the Group class:
Group::make('parent')
  ->label('Parent')
  ->groupQueryUsing(fn($query): string => $query->groupBy(['parent_id','parent_type'])),
Group::make('parent')
  ->label('Parent')
  ->groupQueryUsing(fn($query): string => $query->groupBy(['parent_id','parent_type'])),


I really want this grouping because this table will generate invoice lines and i want to use the bulk select to do this. Any help is appreciated!
Solution
You need both the titleFromRecord AND the groupQueryUsing. This does work. made an attribute on price line and now it groups correct.

Group::make('parent_id')
  ->label('Parent')
  ->getTitleFromRecordUsing(
      fn (PriceLine $record): string => $record->parentName
  )
  ->groupQueryUsing(fn ($query) => $query->groupBy('parentName')),
Group::make('parent_id')
  ->label('Parent')
  ->getTitleFromRecordUsing(
      fn (PriceLine $record): string => $record->parentName
  )
  ->groupQueryUsing(fn ($query) => $query->groupBy('parentName')),
Screenshot_2025-08-22_at_14.48.01.png
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Group Table By Year
FilamentFFilament / ❓┊help
15mo ago
Group By in table
FilamentFFilament / ❓┊help
2y ago
Group by in Table
FilamentFFilament / ❓┊help
3y ago
table group by tenant
FilamentFFilament / ❓┊help
3y ago