public function moveAsRoot()
    {
        if ($this->getIsNewRecord()) {
            throw new Exception('The node should not be new record.');
        }

        if ($this->isRoot()) {
            throw new Exception('The node already is root node.');
        }

        $delta = 1 - $this->lft;
        $this
            ->objects()
            ->filter([
                'lft__gte' => $this->lft,
                'rgt__lte' => $this->rgt,
                'root' => $this->root,
            ])
            ->update([
                'lft' => new Expression('lft' . sprintf('%+d', $delta)),
                'rgt' => new Expression('rgt' . sprintf('%+d', $delta)),
                'level' => new Expression('level' . sprintf('%+d', 1 - $this->level)),
                'root' => $this->getMaxRoot(),
            ]);

        $this
            ->shiftLeftRight($this->rgt + 1, $this->lft - $this->rgt - 1);

        return $this;
    }
public function moveAsRoot()
    {
        if ($this->getIsNewRecord()) {
            throw new Exception('The node should not be new record.');
        }

        if ($this->isRoot()) {
            throw new Exception('The node already is root node.');
        }

        $delta = 1 - $this->lft;
        $this
            ->objects()
            ->filter([
                'lft__gte' => $this->lft,
                'rgt__lte' => $this->rgt,
                'root' => $this->root,
            ])
            ->update([
                'lft' => new Expression('lft' . sprintf('%+d', $delta)),
                'rgt' => new Expression('rgt' . sprintf('%+d', $delta)),
                'level' => new Expression('level' . sprintf('%+d', 1 - $this->level)),
                'root' => $this->getMaxRoot(),
            ]);

        $this
            ->shiftLeftRight($this->rgt + 1, $this->lft - $this->rgt - 1);

        return $this;
    }
public function moveAsRoot ( ) { if ( $ this -> getIsNewRecord ( ) ) { throw new Exception ( 'The node should not be new record.' ) ; } if ( $ this -> isRoot ( ) ) { throw new Exception ( 'The node already is root node.' ) ; } $ delta = 1 - $ this -> lft ; $ this -> objects ( ) -> filter ( [ 'lft__gte' => $ this -> lft , 'rgt__lte' => $ this -> rgt , 'root' => $ this -> root , ] ) -> update ( [ 'lft' => new Expression ( 'lft' . sprintf ( '%+d' , $ delta ) ) , 'rgt' => new Expression ( 'rgt' . sprintf ( '%+d' , $ delta ) ) , 'level' => new Expression ( 'level' . sprintf ( '%+d' , 1 - $ this -> level ) ) , 'root' => $ this -> getMaxRoot ( ) , ] ) ; $ this -> shiftLeftRight ( $ this -> rgt + 1 , $ this -> lft - $ this -> rgt - 1 ) ; return $ this ; }
Move node as new root.

@throws Exception
@throws \Exception

@return $this
Move node as new root .