PHPackages                             malith124/materialized-path - 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. malith124/materialized-path

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

malith124/materialized-path
===========================

Materialized path trait for Laravel 10

1.0.8(1y ago)013MITPHPPHP ^8.0

Since Jan 18Pushed 1y agoCompare

[ Source](https://github.com/Malith1994124/materialized-path)[ Packagist](https://packagist.org/packages/malith124/materialized-path)[ RSS](/packages/malith124-materialized-path/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Materialized path trait for Laravel
-----------------------------------

[](#materialized-path-trait-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/94ade106c1b9772cbb25766aa85938f0ae0b0a7b3a7efcaeb7dc208702052f28/68747470733a2f2f706f7365722e707567782e6f72672f6c616e67616e65722f6d6174657269616c697a65642d706174682f762f737461626c65)](https://packagist.org/packages/langaner/materialized-path)[![Total Downloads](https://camo.githubusercontent.com/fc17312a63ac15795f1de3eb4983b5c677b9eefcb85f74a1c3106794d5e21225/68747470733a2f2f706f7365722e707567782e6f72672f6c616e67616e65722f6d6174657269616c697a65642d706174682f646f776e6c6f616473)](https://packagist.org/packages/langaner/materialized-path)[![Latest Unstable Version](https://camo.githubusercontent.com/7dcefcac09570c2215f4b43a025528c48ab26b2908efd10a9cb5ff4ac48d4dfe/68747470733a2f2f706f7365722e707567782e6f72672f6c616e67616e65722f6d6174657269616c697a65642d706174682f762f756e737461626c65)](https://packagist.org/packages/langaner/materialized-path)[![License](https://camo.githubusercontent.com/fbaaae777aceed62d2f50f84f05df8bef9de0e10161ade4dbf0ea50e61271713/68747470733a2f2f706f7365722e707567782e6f72672f6c616e67616e65722f6d6174657269616c697a65642d706174682f6c6963656e7365)](https://packagist.org/packages/langaner/materialized-path)

### Installation

[](#installation)

1. Add `langaner/materialized-path` to `composer.json`.

```
"langaner/materialized-path": "dev-master"

```

2)Run `composer update` to pull down the latest version of the package.

3)Now open up app/config/app.php and add the service provider to your providers array.

```
Langaner\MaterializedPath\MaterializedPathServiceProvider::class,

```

4)Add the trait to model what need tree implementation

```
use \Langaner\MaterializedPath\MaterializedPathTrait;

```

### Migrations

[](#migrations)

Table migration example `page_table`:

```
	Schema::create('page_table', function(Blueprint $table)
	{
		$table->engine = 'InnoDB';
		$table->increments('id');
		// parent id
        $table->integer('parent_id')->unsigned()->nullable();
        // depth path consisting of models id
        $table->string('path');
        // depth path consisting of models alias
        $table->string('real_path')->unique();
        // alias field
        $table->string('alias')->unique();
        // order position
        $table->integer('position')->default(0)->index();
        // depth level
        $table->integer('level')->default(0)->index();

		$table->foreign('parent_id')->references('id')->on('page_table')->onDelete('cascade');
	});
```

### Available methods

[](#available-methods)

```
	// Make model is root
	with(new Page())->makeRoot();

	// Make model first children by parent id
	with(new Page())->makeFirstChildOf($parentId);

	// Make model last children by parent id
	with(new Page())->makeLastChildOf($parentId);

	// Make previous sibling
	$page = Page::find(2);
	$page->makePreviousSiblingOf(Page::find(1));

	// Make next sibling
	$page = Page::find(2);
	$page->makeNextSiblingOf(Page::find(1));

	// Update model data
	$page = Page::find(1);
	$page->position = 2;
	with(new Page())->updateNode($page);

	// Get parent
	Page::find(1)->parent()->get();

	// Get sibling
	Page::find(1)->sibling()->get();

	// Get childrens by depth
	Page::find(1)->childrenByDepth()->get();

	// Get parents by depth
	Page::find(1)->parentByDepth()->get();

	// Descendant check
	Page::find(1)->isDescendantOf(Page::find(2));

	// Ancestor check
	Page::find(1)->isAncestorOf(Page::find(2));

	// Is leaf
	Page::find(1)->isLeaf();

	// All leafs of model
	Page::allLeaf();

	// All roots of model
	Page::allRoot();

	// Get exploded path
	Page::find(1)->getExplodedPath();

	// Build real path by entities
	with(new Page())->buildRealPath($ids);

	// Build model tree
	Page::find(1)->buildTree();

	// Build model tree by parent id
	Page::find(1)->buildChidrenTree();
```

### Configuration

[](#configuration)

Publish assets `php artisan vendor:publish`

This command initialize config file, located under app/config/packages/langaner/materialized-path/materialized\_path.php.

Set `with_translations` to `true` if you need translation in result model. This option required translation pack `https://github.com/dimsav/laravel-translatable`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.4% 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 ~302 days

Total

3

Last Release

612d ago

PHP version history (2 changes)1.0.6PHP &gt;=5.5.9

1.0.7PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/36a5d578745065994ce52593245a3a666c6668826d167fd2462610563d0eee48?d=identicon)[malith124](/maintainers/malith124)

---

Top Contributors

[![langaner](https://avatars.githubusercontent.com/u/1975620?v=4)](https://github.com/langaner "langaner (13 commits)")[![Malith1994124](https://avatars.githubusercontent.com/u/18634794?v=4)](https://github.com/Malith1994124 "Malith1994124 (6 commits)")

---

Tags

laravellaravel 10databaseeloquentpathtreematerialized

### Embed Badge

![Health badge](/badges/malith124-materialized-path/health.svg)

```
[![Health](https://phpackages.com/badges/malith124-materialized-path/health.svg)](https://phpackages.com/packages/malith124-materialized-path)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[typicms/nestablecollection

A Laravel Package that extends Collection to handle unlimited nested items following adjacency list model.

88327.2k20](/packages/typicms-nestablecollection)[nevadskiy/laravel-tree

Tree-like structure for Eloquent models.

6693.9k4](/packages/nevadskiy-laravel-tree)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)

PHPackages © 2026

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