From 7545019f7f73eac64737d231516cb0b5d22391ab Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 22 Jan 2019 13:58:59 +0100 Subject: [PATCH] Fixed error on non existent parent --- src/Tree.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Tree.php b/src/Tree.php index b4a89a0..fddff5a 100644 --- a/src/Tree.php +++ b/src/Tree.php @@ -202,6 +202,13 @@ public function build($data) $this->nodes = []; $children = []; + // Check for non existent parents + foreach ($data as $i => $item) { + if(!in_array($item['parent_category_id'], array_column($data, 'id'))) { // search value in the array + $data[$i]['parent_category_id'] = ''; + } + } + // Create the root node $this->nodes[$this->rootId] = $this->createNode($this->rootId, null, []);