Exemplo n.º 1
0
 /**
  * Deletes a subtree from database.
  *
  * @param bool $withSelf
  * @param bool $forceDelete
  * @return void
  */
 public function deleteSubtree($withSelf = false, $forceDelete = false)
 {
     $action = $forceDelete === true ? 'forceDelete' : 'delete';
     $ids = $this->joinClosureBy('descendant', $withSelf)->lists($this->getKeyName());
     if ($forceDelete) {
         $this->closure->whereIn($this->closure->getDescendantColumn(), $ids)->delete();
     }
     $this->whereIn($this->getKeyName(), $ids)->{$action}();
 }
Exemplo n.º 2
0
 public function testMoveNodeToBecomeRoot()
 {
     $item = Entity::find(1);
     $item->moveTo(0, 2);
     $item = Entity::find(2);
     $item->moveTo(0, 3);
     $item = Entity::find(3);
     $item->moveTo(0, 4);
     $item = Entity::find(4);
     $item->moveTo(0, 5);
     $item = Entity::find(1);
     $item->moveTo(0);
     $this->assertEquals(1, ClosureTable::whereDescendant(1)->count());
 }