src/Database/NestedSet/Builder.php
public function fixTree()
    {
        $columns = [
            $this->model->getKeyName(),
            $this->model->getParentIdName(),
            $this->model->getLftName(),
            $this->model->getRgtName(),
        ];

        $dictionary = $this->model->newNestedSetQuery()
                                  ->defaultOrder()
                                  ->get($columns)
                                  ->groupBy($this->model->getParentIdName())
                                  ->all();

        return self::fixNodes($dictionary);
    }
public function fixTree()
    {
        $columns = [
            $this->model->getKeyName(),
            $this->model->getParentIdName(),
            $this->model->getLftName(),
            $this->model->getRgtName(),
        ];

        $dictionary = $this->model->newNestedSetQuery()
                                  ->defaultOrder()
                                  ->get($columns)
                                  ->groupBy($this->model->getParentIdName())
                                  ->all();

        return self::fixNodes($dictionary);
    }
Fixes the tree based on parentage info.

Nodes with invalid parent are saved as roots.

@return int The number of fixed nodes