From 2840d14692698bfc167acf8f0374f5407b9f8733 Mon Sep 17 00:00:00 2001 From: Bala Wang Date: Tue, 12 Jan 2021 17:43:52 +0800 Subject: [PATCH] Can create tree with items from different levels --- src/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +}