protected function buildNestedArray(array $nodes = [], $parentId = 0)
    {
        $branch = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            if ($node[$this->parentColumn] === $parentId) {
                $children = $this->buildNestedArray($nodes, $node[$this->getKeyName()]);

                if ($children) {
                    $node['children'] = $children;
                }

                $branch[] = $node;
            }
        }

        return $branch;
    }
protected function buildNestedArray(array $nodes = [], $parentId = 0)
    {
        $branch = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            if ($node[$this->parentColumn] === $parentId) {
                $children = $this->buildNestedArray($nodes, $node[$this->getKeyName()]);

                if ($children) {
                    $node['children'] = $children;
                }

                $branch[] = $node;
            }
        }

        return $branch;
    }
protected function buildNestedArray ( array $ nodes = [ ] , $ parentId = 0 ) { $ branch = [ ] ; if ( empty ( $ nodes ) ) { $ nodes = $ this -> allNodes ( ) ; } foreach ( $ nodes as $ node ) { if ( $ node [ $ this -> parentColumn ] === $ parentId ) { $ children = $ this -> buildNestedArray ( $ nodes , $ node [ $ this -> getKeyName ( ) ] ) ; if ( $ children ) { $ node [ 'children' ] = $ children ; } $ branch [ ] = $ node ; } } return $ branch ; }
Build Nested array.

@param array $nodes
@param int   $parentId

@return array
Build Nested array .