PHPackages                             twocoffeecups/lara-adjacency-list - 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. [Database &amp; ORM](/categories/database)
4. /
5. twocoffeecups/lara-adjacency-list

ActiveLibrary[Database &amp; ORM](/categories/database)

twocoffeecups/lara-adjacency-list
=================================

Lite adjacency list for laravel.

0.2.2.0(2y ago)05MITPHPPHP ^8.0

Since Mar 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/twocoffeecups/lara-adjacency-list)[ Packagist](https://packagist.org/packages/twocoffeecups/lara-adjacency-list)[ RSS](/packages/twocoffeecups-lara-adjacency-list/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Lara Adjacency List
===================

[](#lara-adjacency-list)

Simple plugin for working with a Adjacency List for laravel.

*In dev.*

Compatibility
=============

[](#compatibility)

Laravel 8.x + version.

Installation
============

[](#installation)

Install package:

```
composer require twocoffeecups/lara-adjacency-list

```

Use the HasAdjacencyList trait in your model:

```
use TwoCoffeeCups\LaraAdjacencyList\AdjacencyList\HasAdjacencyList;

class YourModel extends Model
{
    use HasAdjacencyList;
}

```

Add column in your table schema:

```
Schema::create('your_table_name', function (Blueprint $table) {
    $table->id();
    $table->foreignId('parentId')->nullable()->index('parentIdx')->constrained('your_table_name');
});

```

Or run this command if you already have a table in the database and enter table name:

```
php artisan adjacency-list:add-parent-id

```

Usage
=====

[](#usage)

### Keys

[](#keys)

If you already have a table with the parent and local keys, then you can redefine their names in the model:

```
use TwoCoffeeCups\LaraAdjacencyList\AdjacencyList\HasAdjacencyList;

class YourModel extends Model
{
    use HasAdjacencyList;

    public function getLocalIdName(): string
    {
        return 'your_local_id_name';
    }

    public function getParentIdName(): string
    {
        return 'your_parent_id_name';
    }
}

```

### Relationships

[](#relationships)

The trait has various relationships:

- `children()` Get only children nodes.
- `parent()` Get parent node.
- `allAncestors()` Get ancestors list.
- `allAncestorsAndMe()` Get ancestors list, and self.
- `allDescendants()` Get descendants list.
- `allAncestorsAndMe()` Get ancestors list, and self.

Methods usage:

```
$node = Model::find($id);
$node->allAncestors();

```

### Tree

[](#tree)

The static method `getTree()` allows you to get a tree of all elements starting from the roots:

```
$tree = Model::getTree();

```

Get method `descendantsTree()` to create a tree of all descendants:

```
$tree = $model->descendantsTree()->get();

```

The static method `onlyRoots()` allows you to get only the root elements:

```
$roots = Model::onlyRoots();

```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% 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 ~1 days

Total

3

Last Release

832d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/159925336dae3973ec730960351979ce801afe05e530d0e539bfe993a0c16869?d=identicon)[VVAximand94VV](/maintainers/VVAximand94VV)

---

Top Contributors

[![twocoffeecups](https://avatars.githubusercontent.com/u/128425204?v=4)](https://github.com/twocoffeecups "twocoffeecups (10 commits)")[![TTAximand94TT](https://avatars.githubusercontent.com/u/96996829?v=4)](https://github.com/TTAximand94TT "TTAximand94TT (5 commits)")

### Embed Badge

![Health badge](/badges/twocoffeecups-lara-adjacency-list/health.svg)

```
[![Health](https://phpackages.com/badges/twocoffeecups-lara-adjacency-list/health.svg)](https://phpackages.com/packages/twocoffeecups-lara-adjacency-list)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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