code: public function getAncestors($id, $depth = 0)
      {
          static $array;
          if (!$array instanceof ArrayAccess || $depth == 0) {
              $array = collect([]);
          }
          $parent = $this->getParent($id);
          if ($parent) {
              $nextDepth = $depth + 1;
              $array->prepend($parent);   // 添加到开头
              $this->getAncestors($parent->{$this->getTreeNodeIdName()}, $nextDepth);
          }
  
          return $array;
      }
docs: 获取节点的所有祖先.
  
  @param int $id
  @param int $depth
  
  @return array