public static function saveTree($tree = [], $parentId = 0)
{
if (empty(static::$branchOrder)) {
static::setBranchOrder($tree);
}
foreach ($tree as $branch) {
$node = static::find($branch['id']);
$node->parent_id = $parentId;
$node->order = static::$branchOrder[$branch['id']];
$node->save();
if (isset($branch['children'])) {
static::saveTree($branch['children'], $branch['id']);
}
}
}