Skip to content

Commit

Permalink
Fixed error on non existent parent
Browse files Browse the repository at this point in the history
  • Loading branch information
ikwilkoffie committed Jan 22, 2019
1 parent 9e0397e commit 7545019
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);

Expand Down

0 comments on commit 7545019

Please sign in to comment.