efureev / laravel-trees
Multi-Tree structures for Laravel
Installs: 42 278
Dependents: 3
Suggesters: 0
Security: 0
Stars: 132
Watchers: 3
Forks: 17
Open Issues: 2
Requires
- php: ^8.2
- efureev/support: ^4.27 || ^5.0
- illuminate/database: ^11.0 || ^12.0
- illuminate/events: ^11.0 || ^12.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.45
- fakerphp/faker: ^1.23
- orchestra/testbench: ^9.11 || ^10.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- squizlabs/php_codesniffer: ^3.11
- symfony/var-dumper: ^7.0
- dev-master
- v6.x-dev
- v5.x-dev
- v5.3.1
- v5.3.0
- v5.2.1
- v5.2.0
- v5.1.0
- v5.0.0
- v5.0.0-rc2
- v5.0.0-rc1
- v4.0.0
- v3.8.4
- v3.8.3
- v3.8.2
- v3.8.1
- v3.8.0
- v3.7.2
- v3.7.1
- v3.7.0
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- v2.5.0
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.7.5
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- 1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- 1.0.0
- dev-ci
- dev-Healthy
- dev-lara11
- dev-next
- dev-php7
This package is auto-updated.
Last update: 2025-05-30 18:50:11 UTC
README
A Laravel package for implementing multi-tree hierarchical structures using the Nested Set Model.
Overview
This package supports Multi-Tree structures (multiple root nodes) and allows movement of nodes between trees.
It works with various model primary key types: int
, uuid
, and ulid
.
Key Advantages
- Multi-Tree Support: Manage multiple independent trees within the same table
- Cross-Tree Operations: Move nodes between different trees with ease
- Flexible Primary Keys: Works with various key types including
int
,uuid
, andulid
- Comprehensive Tree Health Tools: Built-in validation and repair utilities for tree integrity
- Performance Optimized: Efficiently retrieves hierarchical data with minimal database queries
- Modern PHP Support: Utilizes modern PHP 8.x features and strict typing
- Flexible Configuration: Highly customizable attribute naming and behavior
- Well Documented: Complete documentation with practical examples
- Thoroughly Tested: Comprehensive test suite ensuring reliability
What are nested sets?
Nested Set Model is an efficient way to store hierarchical data in relational databases:
The nested set model numbers nodes according to a tree traversal, which visits each node twice, assigning numbers in the order of visiting, and at both visits. This leaves two numbers for each node, which are stored as attributes. Querying becomes inexpensive: hierarchy membership can be tested by comparing these numbers. Updating requires renumbering and is therefore expensive.
Ideal Use Cases
NSM shows good performance when:
- Trees are updated infrequently
- Fast retrieval of related nodes is needed
- Building multi-depth menus or category structures
Visualization


Requirements
- PHP: 8.2|8.3|8.4
- Laravel: ^11.*
It is highly recommended to use a database that supports transactions (like PostgreSQL) to protect tree structures from corruption.
Installation
composer require efureev/laravel-trees
Documentation
- Basic Usage
- Advanced Tree Configuration
- Database Migration
- Creating Nodes
- Managing Nodes
- Retrieving Nodes
- Model Helpers
- Console Commands
- Health Checks and Fixing
Testing
./vendor/bin/phpunit --testdox # or composer test