chel7ch / nestedsets
Nested Set Model
dev-master
2022-05-19 14:33 UTC
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- ext-pdo: *
- illuminate/database: ^8.0.
Requires (Dev)
- phpunit/phpunit: ^7.1
This package is auto-updated.
Last update: 2025-06-19 21:32:29 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();