PHPackages                             efureev/laravel-trees - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. efureev/laravel-trees

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

efureev/laravel-trees
=====================

Multi-Tree structures for Laravel

v6.1.0(2mo ago)14257.6k↓20.8%21[2 issues](https://github.com/efureev/laravel-trees/issues)3MITPHPPHP &gt;=8.4CI passing

Since Feb 8Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/efureev/laravel-trees)[ Packagist](https://packagist.org/packages/efureev/laravel-trees)[ RSS](/packages/efureev-laravel-trees/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (30)Versions (100)Used By (3)

Laravel Tree Structure
======================

[](#laravel-tree-structure)

[![PHP Laravel Package](https://github.com/efureev/laravel-trees/workflows/PHP%20Laravel%20Package/badge.svg?branch=master)](https://github.com/efureev/laravel-trees/workflows/PHP%20Laravel%20Package/badge.svg?branch=master)[![PHP Version](https://camo.githubusercontent.com/6b697dbbeb677875e7ba349eb056aeca6ca363db1f4b438510b34e7aa79bcc71/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e34253743382e352d626c75652e737667)](https://camo.githubusercontent.com/6b697dbbeb677875e7ba349eb056aeca6ca363db1f4b438510b34e7aa79bcc71/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e34253743382e352d626c75652e737667)[![Laravel Version](https://camo.githubusercontent.com/c8cc647ce4d85986f7aee88e8c0b57ed8c8c5edec49c8ca3a80ec9f4dac61e70/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31332e2a2d7265642e737667)](https://camo.githubusercontent.com/c8cc647ce4d85986f7aee88e8c0b57ed8c8c5edec49c8ca3a80ec9f4dac61e70/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31332e2a2d7265642e737667)[![Total Downloads](https://camo.githubusercontent.com/b28b4247ce78b0a83e04eb81f645cdc28ccd3fa2139d421046fa2a7e53145ad2/68747470733a2f2f706f7365722e707567782e6f72672f656675726565762f6c61726176656c2d74726565732f646f776e6c6f616473)](https://packagist.org/packages/efureev/laravel-trees)[![License](https://camo.githubusercontent.com/168c7161009eef1cace44070f0f16f331ae2e965a795bfbd5e39ff5c414d554b/68747470733a2f2f706f7365722e707567782e6f72672f656675726565762f6c61726176656c2d74726565732f6c6963656e7365)](https://packagist.org/packages/efureev/laravel-trees)[![composer.lock available](https://camo.githubusercontent.com/455feb0191da47195d175cc5c9fa9dad8ba237cc92718fca5dd51f63822db231/68747470733a2f2f706f7365722e707567782e6f72672f656675726565762f6c61726176656c2d74726565732f636f6d706f7365726c6f636b)](https://packagist.org/packages/efureev/laravel-trees)[![Latest Stable Version](https://camo.githubusercontent.com/dbb9cafcd80f37ca1075f180906bc94ff8717f1e104dd41e5d718d2b2721426d/68747470733a2f2f706f7365722e707567782e6f72672f656675726565762f6c61726176656c2d74726565732f76657273696f6e)](https://packagist.org/packages/efureev/laravel-trees)[![Maintainability](https://camo.githubusercontent.com/b32608efefb27bbe0971796c06bc9ad786942bb9aa6bbf01dc29deb3d909e552/68747470733a2f2f716c74792e73682f67682f656675726565762f70726f6a656374732f6c61726176656c2d74726565732f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/efureev/projects/laravel-trees)[![Code Coverage](https://camo.githubusercontent.com/0ce84a069215a9c58cf459aa08fa4bdccf5c40cedf67031e6566ed4283d95411/68747470733a2f2f716c74792e73682f67682f656675726565762f70726f6a656374732f6c61726176656c2d74726565732f636f7665726167652e737667)](https://qlty.sh/gh/efureev/projects/laravel-trees)[![PHPStan Level](https://camo.githubusercontent.com/9c993481c3bca6625658657a2812cdd8bec2daf7aae7cd224d244dfb77935a33/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230352d627269676874677265656e3f7374796c653d666c6174)](https://camo.githubusercontent.com/9c993481c3bca6625658657a2812cdd8bec2daf7aae7cd224d244dfb77935a33/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230352d627269676874677265656e3f7374796c653d666c6174)

A Laravel package for implementing multi-tree hierarchical structures using the Nested Set Model.

Overview
--------

[](#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
--------------

[](#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`, and `ulid`
- **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?

[](#what-are-nested-sets)

[Nested Set Model](http://en.wikipedia.org/wiki/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

[](#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
-------------

[](#visualization)

 [![html tree](./docs/assets/tree.png)](./docs/assets/tree.png) [![console tree](./docs/assets/table.png)](./docs/assets/table.png)

Requirements
------------

[](#requirements)

- PHP: &gt;= 8.4
- Laravel: &gt;= 13.0

It is highly recommended to use a database that supports transactions (like PostgreSQL) to protect tree structures from corruption.

Installation
------------

[](#installation)

```
composer require efureev/laravel-trees
```

Documentation
-------------

[](#documentation)

- [Basic Usage](./docs/Basic.md)
- [Advanced Tree Configuration](./docs/AdvancedTreeConfig.md)
- [Database Migration](./docs/Migration.md)
- [Creating Nodes](./docs/CreatingNodes.md)
- [Managing Nodes](./docs/ManagingNodes.md)
- [Retrieving Nodes](./docs/ReceivingNodes.md)
- [Model Helpers](./docs/Helpers.md)
- [Console Commands](./docs/Console.md)
- [Health Checks and Fixing](./docs/HealthAndFix.md)

Testing
-------

[](#testing)

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
```

###  Health Score

68

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity95

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Recently: every ~37 days

Total

92

Last Release

74d ago

Major Versions

v1.7.5 → v2.0.02020-05-18

v2.5.0 → v3.0.02021-04-28

v3.8.4 → v4.0.02024-03-14

v4.0.0 → v5.0.0-rc12024-04-02

v5.6.0 → v6.x-dev2026-06-05

PHP version history (9 changes)v2.0.2PHP &gt;=7.4

v2.2.0PHP ^7.4|^8.0

v3.0.0PHP ^8.0

v3.7.0PHP ^8.0|^8.1

v3.8.0PHP ^8.0|^8.1|^8.2

v4.0.0PHP ^8.2|^8.3

v5.1.0PHP ^8.2|^8.3|^8.4

v5.2.0PHP ^8.2

v6.x-devPHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/62a6e061d1ccab4d5de8dcba717b7634f91e4842b32ca26420b8261c66104bf7?d=identicon)[efureev](/maintainers/efureev)

---

Top Contributors

[![efureev](https://avatars.githubusercontent.com/u/5524684?v=4)](https://github.com/efureev "efureev (154 commits)")[![dikopylov](https://avatars.githubusercontent.com/u/38421064?v=4)](https://github.com/dikopylov "dikopylov (2 commits)")[![veelasky](https://avatars.githubusercontent.com/u/1797358?v=4)](https://github.com/veelasky "veelasky (2 commits)")[![mpge](https://avatars.githubusercontent.com/u/3311227?v=4)](https://github.com/mpge "mpge (1 commits)")[![bistory](https://avatars.githubusercontent.com/u/108102?v=4)](https://github.com/bistory "bistory (1 commits)")[![ZinoviL](https://avatars.githubusercontent.com/u/9405816?v=4)](https://github.com/ZinoviL "ZinoviL (1 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (1 commits)")[![Khazhinov](https://avatars.githubusercontent.com/u/15653986?v=4)](https://github.com/Khazhinov "Khazhinov (1 commits)")

---

Tags

laravelnestedsetphptreetree-structurephplaravelpackagetreemulti-tree

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/efureev-laravel-trees/health.svg)

```
[![Health](https://phpackages.com/badges/efureev-laravel-trees/health.svg)](https://phpackages.com/packages/efureev-laravel-trees)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M110](/packages/mongodb-laravel-mongodb)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[flat3/lodata

OData v4.01 Producer for Laravel

100357.6k](/packages/flat3-lodata)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7213.1k](/packages/tehwave-laravel-achievements)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
