PHPackages                             laraditz/laravel-tree - 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. laraditz/laravel-tree

ActiveLibrary

laraditz/laravel-tree
=====================

Hierarchical or tree database implementation using path enumeration model

0.0.3(11mo ago)1120MITPHPPHP ^7.4|^8.0

Since Mar 24Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/laraditz/laravel-tree)[ Packagist](https://packagist.org/packages/laraditz/laravel-tree)[ Docs](https://github.com/laraditz/laravel-tree)[ RSS](/packages/laraditz-laravel-tree/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Laravel Tree
============

[](#laravel-tree)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ba29295e84bb9af2a2af2665e121e26aa22c637327e2d3ab7cf23ff10ed24723/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6172616469747a2f6c61726176656c2d747265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laraditz/laravel-tree)[![Build Status](https://camo.githubusercontent.com/ba488e923f380ef273a9511277db7bb3c7404c3944789b8fe58a93c9942e7e4a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c6172616469747a2f6c61726176656c2d747265652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/laraditz/laravel-tree)[![Quality Score](https://camo.githubusercontent.com/8e0198b7316d56183e1294b661121779745590215659c1d56d675d403aacd78d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c6172616469747a2f6c61726176656c2d747265652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/laraditz/laravel-tree)[![Total Downloads](https://camo.githubusercontent.com/a9d9a78219a4e5a873de0540fffe48b80fdeae40c25775c67bf2976fc501af9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6172616469747a2f6c61726176656c2d747265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laraditz/laravel-tree)

Hierarchical or tree database implementation using path enumeration model.

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

[](#installation)

You can install the package via composer:

```
composer require laraditz/laravel-tree
```

Configuration
-------------

[](#configuration)

Add the tree columns to your table by adding `addLaravelTreeColumns` to your database migration file. For example, we add the tree columns to the `trees` table as shown below.

```
 Schema::create('trees', function (Blueprint $table) {
    ...
    $table->addLaravelTreeColumns();
    ...
});
```

Then, add the `HasTreeNode` to the model.

```
use Laraditz\LaravelTree\HasTreeNode;

class Tree extends Model
{
    use HasTreeNode;

}
```

Usage
-----

[](#usage)

Create node as root.

```
Tree::create([
    'user_id' => 1
])->asRoot()
```

Create node as child.

```
// $tree is the parent object
Tree::create([
    'user_id' => 2
])->asChildOf($tree);

// or
$tree->appendChild([
    'user_id' => 2
]);
```

Available Relationships
-----------------------

[](#available-relationships)

Below are all relationships under the `HasTreeNode`.

Relationship nameDescriptionparent()Parent of current node. (1-1)child()Children of current node. (1-N)Available Attributes
--------------------

[](#available-attributes)

Below are all attributes under the `HasTreeNode`.

Attribute nameDescriptionchild\_countGet number of children.direct\_child\_countGet number of cirect children.has\_childCheck if children exists.Available Methods
-----------------

[](#available-methods)

Below are all methods under the `HasTreeNode`.

Method nameDescriptiongetChildCount()Count number of children.getChildCount(int $level)Count number of children based on level.getDirectChildCount()Count number of cirect children.getParentIds()Get parent ids from bottom-up.moveNode($node)Move node to new parent $node.isChildOf($node)Check is current node is child or distinct child of $node.isSameTree($node)Check is current node is from the same tree as $node.isRootNode()Check if current node is a root node.isSameNode($node)Compare two nodes is the same or not.### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Raditz Farhan](https://github.com/laraditz)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance54

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~768 days

Total

3

Last Release

336d ago

PHP version history (2 changes)0.0.1PHP ^7.1

0.0.2PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1203676?v=4)[Raditz Farhan](/maintainers/raditzfarhan)[@raditzfarhan](https://github.com/raditzfarhan)

---

Top Contributors

[![raditzfarhan](https://avatars.githubusercontent.com/u/1203676?v=4)](https://github.com/raditzfarhan "raditzfarhan (24 commits)")[![farhan928](https://avatars.githubusercontent.com/u/8623033?v=4)](https://github.com/farhan928 "farhan928 (1 commits)")

---

Tags

laraditzlaravel-tree

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laraditz-laravel-tree/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M682](/packages/barryvdh-laravel-ide-helper)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[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.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)[jiaxincui/closure-table

A closure table tree package for laravel eloquent

1138.4k](/packages/jiaxincui-closure-table)[aedart/athenaeum

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

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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