Grouping Rows with Closure/Tree relation
So i have a table in this shape:
I want to group them by the root(topmost ancestor)
I tried to do this
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
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)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
