src/Tree/Traits/TreeTrait.php
public function getDescendants($parentId, $depth = 0, $adds = '')
    {
        static $array;
        if (!$array instanceof ArrayAccess || $depth == 0) {
            $array = collect([]);
        }
        $number = 1;
        $child = $this->getSubLevel($parentId);
        if ($child) {
            $nextDepth = $depth + 1;
            $total = $child->count();
            foreach ($child as $val) {
                $j = $k = '';
                if ($number == $total) {
                    $j .= $this->getTreeLastIcon();
                    $k = $this->getTreeSpacer();
                } else {
                    $j .= $this->getTreeMiddleIcon();
                    $k = $adds ? $this->getTreeFirstIcon() : '';
                }

                $val->spacer = $adds ? ($adds.$j) : '';

                $val->depth = $depth;
                $array->put($val->{$this->getTreeNodeIdName()}, $val);
                $this->getDescendants(
                    $val->{$this->getTreeNodeIdName()},
                    $nextDepth,
                    $adds.$k.$this->getTreeSpacer()
                );
                ++$number;
            }
        }

        return $array;
    }
public function getDescendants($parentId, $depth = 0, $adds = '')
    {
        static $array;
        if (!$array instanceof ArrayAccess || $depth == 0) {
            $array = collect([]);
        }
        $number = 1;
        $child = $this->getSubLevel($parentId);
        if ($child) {
            $nextDepth = $depth + 1;
            $total = $child->count();
            foreach ($child as $val) {
                $j = $k = '';
                if ($number == $total) {
                    $j .= $this->getTreeLastIcon();
                    $k = $this->getTreeSpacer();
                } else {
                    $j .= $this->getTreeMiddleIcon();
                    $k = $adds ? $this->getTreeFirstIcon() : '';
                }

                $val->spacer = $adds ? ($adds.$j) : '';

                $val->depth = $depth;
                $array->put($val->{$this->getTreeNodeIdName()}, $val);
                $this->getDescendants(
                    $val->{$this->getTreeNodeIdName()},
                    $nextDepth,
                    $adds.$k.$this->getTreeSpacer()
                );
                ++$number;
            }
        }

        return $array;
    }
获取指定节点的所有后代.

@param mixed  $parentId
@param int    $depth
@param string $adds

@return \Illuminate\Support\Collection