diff --git a/src/Collection.php b/src/Collection.php index 2dd26df..118c911 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -64,7 +64,7 @@ public function toTree($root = false) /** @var Model|NodeTrait $node */ foreach ($this->items as $node) { - if ($node->getParentId() == $root) { + if ($node->getParentId() == $root || ! $node->getParentId()) { $items[] = $node; } } @@ -140,4 +140,4 @@ protected function flattenTree(self $groupedNodes, $parentId) return $this; } -} \ No newline at end of file +}