PHPackages                             lordsimal/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. lordsimal/laravel-trees

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

lordsimal/laravel-trees
=======================

Multi-Tree structures for Laravel

01.0k↓33.3%PHPCI passing

Since Mar 23Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/LordSimal/laravel-trees)[ Packagist](https://packagist.org/packages/lordsimal/laravel-trees)[ RSS](/packages/lordsimal-laravel-trees/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/3bffaaf01553c97330e2aaead4ab024eb9112b2ecc09186506c2ce62cc3ec8a9/687474703a2f2f706f7365722e707567782e6f72672f6c6f726473696d616c2f6c61726176656c2d74726565732f76)](https://packagist.org/packages/lordsimal/laravel-trees)[![Total Downloads](https://camo.githubusercontent.com/f4a134c94281847117fc30e6656a98c565177c9ddb98b04db9ba6850c6413240/687474703a2f2f706f7365722e707567782e6f72672f6c6f726473696d616c2f6c61726176656c2d74726565732f646f776e6c6f616473)](https://packagist.org/packages/lordsimal/laravel-trees)[![Latest Unstable Version](https://camo.githubusercontent.com/5d3a7c9a75fc5bc696f67efba844674c79b504aad126eafa206dac3c20d1c679/687474703a2f2f706f7365722e707567782e6f72672f6c6f726473696d616c2f6c61726176656c2d74726565732f762f756e737461626c65)](https://packagist.org/packages/lordsimal/laravel-trees)[![License](https://camo.githubusercontent.com/6641aa93bb62c39a6c963afc4943b8c4b2a82d06176d3742345a91c06305ed5f/687474703a2f2f706f7365722e707567782e6f72672f6c6f726473696d616c2f6c61726176656c2d74726565732f6c6963656e7365)](https://packagist.org/packages/lordsimal/laravel-trees)[![PHP Version Require](https://camo.githubusercontent.com/161b3108325a65a54e68287fd21e6ba363afe0d8544ce26911cac5623e252007/687474703a2f2f706f7365722e707567782e6f72672f6c6f726473696d616c2f6c61726176656c2d74726565732f726571756972652f706870)](https://packagist.org/packages/lordsimal/laravel-trees)[![codecov](https://camo.githubusercontent.com/0b881c3141dd88cf39919e821712b4648b89e4d7283d2cbc4685feddbb51af04/68747470733a2f2f636f6465636f762e696f2f67682f4c6f726453696d616c2f6c61726176656c2d74726565732f67726170682f62616467652e7376673f746f6b656e3d684356554a7952623344)](https://codecov.io/gh/LordSimal/laravel-trees)

Laravel Trees
=============

[](#laravel-trees)

**Contents:**

- [Theory](#information)
- [Installation](#installation)
- [Documentation](#documentation)
    - [Basic](docs/Basic.md)
    - [AdvancedTreeConfig](docs/AdvancedTreeConfig.md)
    - [Migration](docs/Migration.md)
    - [Creating Nodes](docs/CreatingNodes.md)
    - [Managing Nodes](docs/ManagingNodes.md)
    - [Receiving Nodes](docs/ReceivingNodes.md)
    - [Model's Helpers](docs/Helpers.md)
    - [Console](docs/Console.md)
    - [Health And Fixing.md](docs/HealthAndFix.md)

Information
-----------

[](#information)

This package allows to have a single root or multi root tree structure in your Laravel application.

### What are nested sets?

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

Nested sets or [Nested Set Model](http://en.wikipedia.org/wiki/Nested_set_model) is a way to effectively store hierarchical data in a relational table. From wikipedia:

> The nested set model is to number the 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 two attributes. Querying becomes inexpensive: hierarchy membership can be tested by comparing these numbers. Updating requires renumbering and is therefore expensive.

### Applications

[](#applications)

NSM shows good performance when tree is updated rarely. It is tuned to be fast for getting related nodes. It is ideally suited for building multi-depth menu or categories for shop.

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

[](#requirements)

- PHP: 8.2+
- Laravel: ^11.\*|^12.\*

It is highly suggested to use database that supports transactions (like Postgres) to secure a tree from possible corruption.

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

[](#installation)

```
composer require lordsimal/laravel-trees
```

Testing
-------

[](#testing)

The testing environment expects a PostgreSQL database to be available via localhost:5432

You can use the provided `docker-compose.yml` file to start a PostgreSQL database via `docker-compose up`.

After that you can run the tests with:

```
./vendor/bin/phpunit
# or
composer test
```

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

[](#documentation)

The package allows to create multi-root structures: no only-one-root! And allows to move nodes between trees.
Moreover, it also works with different model's primary key: `int`, `uuid`, `ulid`.

- [Basic](docs/Basic.md)
- [AdvancedTreeConfig](docs/AdvancedTreeConfig.md)
- [Migration](docs/Migration.md)
- [Creating Nodes](docs/CreatingNodes.md)
- [Managing Nodes](docs/ManagingNodes.md)
- [Receiving Nodes](docs/ReceivingNodes.md)
- [Model's Helpers](docs/Helpers.md)
- [Console](docs/Console.md)
- [Health And Fixing.md](docs/HealthAndFix.md)

Credit where credit is due
--------------------------

[](#credit-where-credit-is-due)

This plugin is based on the [Laravel Tree Structure from Eugene Fureev](https://github.com/efureev/laravel-trees)

License
-------

[](#license)

The plugin is available as open source under the terms of the [MIT License](https://github.com/lordsimal/laravel-trees/blob/main/LICENSE).

###  Health Score

23

—

LowBetter than 25% of packages

Maintenance51

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bfa3748cb4e1bf824128dc4b23bce7f80654dd560a002048c89c567ef67c0928?d=identicon)[LordSimal](/maintainers/LordSimal)

---

Top Contributors

[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (10 commits)")

### Embed Badge

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

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

###  Alternatives

[christeredvartsen/php-bittorrent

A set of components that can be used to interact with torrent files (read+write) and classes that can encode/decode to/from the BitTorrent format.

11020.6k2](/packages/christeredvartsen-php-bittorrent)[adamhopkinson/laravel-model-hash

A trait which automatically generates a unique hash per model instance

2328.3k](/packages/adamhopkinson-laravel-model-hash)[overtrue/laravel-stateless-session

A lightweight middleware to make api routing session capable.

186.1k](/packages/overtrue-laravel-stateless-session)

PHPackages © 2026

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