Skip to content

Commit 6f2a859

Browse files
Fixed an issue where tree would go into inf loop
1 parent 4bfb19f commit 6f2a859

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/SelectTree.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protected function setUp(): void
8484
private function buildTree($parent = null): array|Collection
8585
{
8686
// Assign the parent's null value to the $parent variable if it's not null
87-
$parent = $this->getParentNullValue() ?? $parent;
87+
if ($parent == null || $parent == $this->getParentNullValue()) {
88+
$parent = $this->getParentNullValue() ?? $parent;
89+
}
8890

8991
// Create a default query to retrieve related items.
9092
$defaultQuery = $this->getRelationship()
@@ -93,7 +95,7 @@ private function buildTree($parent = null): array|Collection
9395
->where($this->getParentAttribute(), $parent);
9496

9597
// If we're not at the root level and a modification callback is provided, apply it to the query.
96-
if (! $parent && $this->modifyQueryUsing) {
98+
if (!$parent && $this->modifyQueryUsing) {
9799
$defaultQuery = $this->evaluate($this->modifyQueryUsing, ['query' => $defaultQuery]);
98100
}
99101

0 commit comments

Comments
 (0)