chel7ch/nestedsets

Nested Set Model

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/chel7ch/nestedsets

dev-master 2022-05-19 14:33 UTC

This package is auto-updated.

Last update: 2026-01-19 22:52:12 UTC


README

Laravel package for working with trees in databases.

Theory: https://webscript.ru/stories/04/09/01/8197045

Using

Each node has 3 unique indexes: id , lk and rk. To start manipulating the nodes of the tree, we learn the attributes of the node:

$prop=array('id'=>5, 'lk'=>3, 'rk'=>8); 

or any part of:

$prop=array('lk'=>3);

$node=(new Node)->prepare($prop);

Select

the entire branch in which our node participates:

$tree = new Categories();
$tree->getEntireBranch($node);

ancestors of node:

$tree->getAncestors($node);

ancestors of the node and node together:

$tree->getAncestorNode($node);

Node's descendants:

$tree->getDescendant($node);

the descendants with a node:

$tree->getDescendantNode($node);

all tree:

$tree->getTree();

Add node

only child node:

$tree->createNode($parantNode, $nodeName);

rename a node:

$tree->renameNode($node, $newName)

delete a node with descendants:

$tree->deleteNode($node);

clear everything:

$tree->cleanTree();

move a node:

$tree->moveNode($node, $newParent);

check the integrity of the tree:

$check= new CheckOfTree(new Categories);
$check->inspect();