efureev/laravel-trees is a Laravel package for multi-tree structures for laravel.
It currently has 142 GitHub stars and 55.969 downloads on Packagist (latest version v6.1.0).
Install it with composer require efureev/laravel-trees.
Discover more Laravel packages by efureev
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package for implementing multi-tree hierarchical structures using the Nested Set Model.
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.
int, uuid, and ulidNested 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.
NSM shows good performance when:
It is highly recommended to use a database that supports transactions (like PostgreSQL) to protect tree structures from corruption.
composer require efureev/laravel-trees
The test suite runs against PostgreSQL. If you don't have PostgreSQL installed locally, use the bundled Docker setup (PostgreSQL 18):
# Run the whole test suite inside Docker (spins up PostgreSQL 18 automatically)
composer test:docker
Or run the tests directly against an available PostgreSQL instance:
DB_HOST=localhost DB_PORT=5432 DB_DATABASE=forge DB_USERNAME=forge DB_PASSWORD=forge composer test
# or
./vendor/bin/phpunit --testdox