© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
5 replies
loco

Grouping Rows with Closure/Tree relation

So i have a table in this shape:

Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->unsignedInteger('parent_product_id')->nullable();  //foreign key to self
        });

Schema::create('products_closure', function (Blueprint $table) {
            $table->unsignedInteger('ancestor');
            $table->unsignedInteger('descendant');
            $table->unsignedTinyInteger('distance');
            $table->primary(['ancestor', 'descendant']);
        });
Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->unsignedInteger('parent_product_id')->nullable();  //foreign key to self
        });

Schema::create('products_closure', function (Blueprint $table) {
            $table->unsignedInteger('ancestor');
            $table->unsignedInteger('descendant');
            $table->unsignedTinyInteger('distance');
            $table->primary(['ancestor', 'descendant']);
        });


I want to group them by the root(topmost ancestor)

I tried to do this
Group::make('name')
                    ->getTitleFromRecordUsing(fn (Product $record) => $record->getRoot()->name ?? $record->name)
                    ->getKeyFromRecordUsing(fn (Product $record) => $record->getRoot()->id ?? $record->id)
Group::make('name')
                    ->getTitleFromRecordUsing(fn (Product $record) => $record->getRoot()->name ?? $record->name)
                    ->getKeyFromRecordUsing(fn (Product $record) => $record->getRoot()->id ?? $record->id)

but it doesnt seem to group.
It shows as such

Any suggestions?
The first and third group should be one but because the name differs, they are seperated
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Grouping Rows with Actions
FilamentFFilament / ❓┊help
13mo ago
Grouping rows - default orderQueryUsing
FilamentFFilament / ❓┊help
2y ago
Grouping rows - changing color
FilamentFFilament / ❓┊help
2y ago
Table with sub-rows tree
FilamentFFilament / ❓┊help
3y ago