Baum\Extensions\Eloquent\Collection::hierarchical PHP Метод

hierarchical() защищенный Метод

protected hierarchical ( $result )
    protected function hierarchical($result)
    {
        foreach ($result as $key => $node) {
            $node->setRelation('children', new BaseCollection());
        }
        $nestedKeys = [];
        foreach ($result as $key => $node) {
            $parentKey = $node->getParentId();
            if (!is_null($parentKey) && array_key_exists($parentKey, $result)) {
                $result[$parentKey]->children[] = $node;
                $nestedKeys[] = $node->getKey();
            }
        }
        foreach ($nestedKeys as $key) {
            unset($result[$key]);
        }
        return $result;
    }