src/Franzose/ClosureTable/Models/ClosureTable.php
public function moveNodeTo($ancestorId = null)
    {
        $table = $this->getPrefixedTable();
        $ancestor = $this->getAncestorColumn();
        $descendant = $this->getDescendantColumn();
        $depth = $this->getDepthColumn();

        $thisAncestorId = $this->ancestor;
        $thisDescendantId = $this->descendant;

        // Prevent constraint collision
        if (!is_null($ancestorId) && $thisAncestorId === $ancestorId) {
            return;
        }

        $this->unbindRelationships();

        // Since we have already unbound the node relationships,
        // given null ancestor id, we have nothing else to do,
        // because now the node is already root.
        if (is_null($ancestorId)) {
            return;
        }

        $query = "
            INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth})
            SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1
            FROM {$table} as supertbl
            CROSS JOIN {$table} as subtbl
            WHERE supertbl.{$descendant} = {$ancestorId}
            AND subtbl.{$ancestor} = {$thisDescendantId}
        ";

        DB::connection($this->connection)->statement($query);
    }
public function moveNodeTo($ancestorId = null)
    {
        $table = $this->getPrefixedTable();
        $ancestor = $this->getAncestorColumn();
        $descendant = $this->getDescendantColumn();
        $depth = $this->getDepthColumn();

        $thisAncestorId = $this->ancestor;
        $thisDescendantId = $this->descendant;

        // Prevent constraint collision
        if (!is_null($ancestorId) && $thisAncestorId === $ancestorId) {
            return;
        }

        $this->unbindRelationships();

        // Since we have already unbound the node relationships,
        // given null ancestor id, we have nothing else to do,
        // because now the node is already root.
        if (is_null($ancestorId)) {
            return;
        }

        $query = "
            INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth})
            SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1
            FROM {$table} as supertbl
            CROSS JOIN {$table} as subtbl
            WHERE supertbl.{$descendant} = {$ancestorId}
            AND subtbl.{$ancestor} = {$thisDescendantId}
        ";

        DB::connection($this->connection)->statement($query);
    }
public function moveNodeTo ( $ ancestorId = null ) { $ table = $ this -> getPrefixedTable ( ) ; $ ancestor = $ this -> getAncestorColumn ( ) ; $ descendant = $ this -> getDescendantColumn ( ) ; $ depth = $ this -> getDepthColumn ( ) ; $ thisAncestorId = $ this -> ancestor ; $ thisDescendantId = $ this -> descendant ; // Prevent constraint collision if ( ! is_null ( $ ancestorId ) && $ thisAncestorId === $ ancestorId ) { return ; } $ this -> unbindRelationships ( ) ; // Since we have already unbound the node relationships, // given null ancestor id, we have nothing else to do, // because now the node is already root. if ( is_null ( $ ancestorId ) ) { return ; } $ query = "
            INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth})
            SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1
            FROM {$table} as supertbl
            CROSS JOIN {$table} as subtbl
            WHERE supertbl.{$descendant} = {$ancestorId}
            AND subtbl.{$ancestor} = {$thisDescendantId}
        " ; DB :: connection ( $ this -> connection ) -> statement ( $ query ) ; }
Make a node a descendant of another ancestor or makes it a root node.

@param int $ancestorId
@return void
@throws \InvalidArgumentException
Make a node a descendant of another ancestor or makes it a root node .