code: public function getRoot() {
      if ( $this->exists ) {
        return $this->ancestorsAndSelf()->whereNull($this->getParentColumnName())->first();
      } else {
        $parentId = $this->getParentId();
  
        if ( !is_null($parentId) && $currentParent = static::find($parentId) ) {
          return $currentParent->getRoot();
        } else {
          return $this;
        }
      }
    }
docs: Returns the root node starting at the current node.
  
  @return NestedSet