Skip to content

Commit f4ec697

Browse files
committed
Fix eager loading of parent relation in page tree
1 parent 7eae2d7 commit f4ec697

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Resources/PageResource/Pages/ManagePageTree.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Statikbe\FilamentFlexibleContentBlockPages\Resources\PageResource\Pages;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Database\Eloquent\Model;
67
use SolutionForest\FilamentTree\Actions\EditAction;
78
use SolutionForest\FilamentTree\Actions\ViewAction;
@@ -83,4 +84,18 @@ public function getTreeRecordIcon(?Model $record = null): ?string
8384

8485
return null;
8586
}
87+
88+
/**
89+
* Overwritten to eager load parent relationship.
90+
* {@inheritDoc}
91+
*/
92+
protected function getWithRelationQuery(): Builder
93+
{
94+
$query = parent::getWithRelationQuery();
95+
if (method_exists($this->getModel(), 'parent') && $this->getModel()::has('parent')) {
96+
return $query->with('parent');
97+
}
98+
99+
return $query;
100+
}
86101
}

0 commit comments

Comments
 (0)