PHPackages                             lattice-php/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. lattice-php/tree

ActiveLibrary

lattice-php/tree
================

Tree view component for Lattice — hierarchy rendering from callback or Eloquent adjacency-list sources.

0.1.0(yesterday)00[2 PRs](https://github.com/lattice-php/tree/pulls)MITPHPPHP ^8.4CI passing

Since Jul 19Pushed todayCompare

[ Source](https://github.com/lattice-php/tree)[ Packagist](https://packagist.org/packages/lattice-php/tree)[ RSS](/packages/lattice-php-tree/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (6)Versions (7)Used By (0)

Lattice Tree
============

[](#lattice-tree)

Tree view component for [Lattice](https://github.com/lattice-php/lattice) — hierarchy rendering from inline nodes, callbacks, or Eloquent adjacency-list sources, with full keyboard navigation (roving tabindex, typeahead), per-node icons, badges, links, and actions, and lazy child loading over a signed endpoint.

Extracted from the Lattice core package to grow on its own; drag &amp; drop reordering is next on the roadmap.

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

[](#installation)

```
composer require lattice-php/tree
```

That is the whole integration: the package ships its React renderer as source and Lattice's `lattice()` Vite plugin compiles it into your app's bundle via `virtual:lattice/plugins`. The PHP classes are picked up by Lattice's discovery and TypeScript generation automatically.

Usage
-----

[](#usage)

```
use Lattice\Tree\Tree;
use Lattice\Tree\TreeNode;

Tree::make('categories')->nodes([
    TreeNode::make('Electronics', 'electronics')
        ->icon('cpu')
        ->children([
            TreeNode::make('Laptops', 'electronics-laptops'),
            TreeNode::make('Phones', 'electronics-phones')->href('/products/phones'),
        ]),
])->defaultExpanded(['electronics']);
```

Or back it with an Eloquent adjacency list (a self-referencing `parent_id` column):

```
use Lattice\Tree\EloquentTreeSource;

Tree::make('categories')->source(
    EloquentTreeSource::make(Category::class)
        ->scope(fn ($query) => $query->where('active', true)),
);
```

Any other backing store implements the two-method `Lattice\Tree\TreeSource` contract.

Lazy loading
------------

[](#lazy-loading)

Serializing a large hierarchy eagerly is wasteful. Register a tree definition and let expansion fetch one level per request instead:

```
use Lattice\Tree\AsTree;
use Lattice\Tree\EloquentTreeSource;
use Lattice\Tree\TreeDefinition;
use Lattice\Tree\TreeSource;

#[AsTree('categories')]
class CategoryTree extends TreeDefinition
{
    public function source(): TreeSource
    {
        return EloquentTreeSource::make(Category::class);
    }
}
```

```
Tree::use(CategoryTree::class)->lazy();     // roots eager, deeper levels fetched on expand
Tree::use(CategoryTree::class)->lazy(2);    // two levels eager
Tree::use(CategoryTree::class)->lazy(0);    // bare skeleton — even the roots are fetched
```

The definition is discovered like any Lattice definition (`#[AsTree]` + Lattice's discovery paths), and the serialized tree carries a sealed reference — the same signing machinery Lattice tables use — that the package's `lattice/trees/{tree}` endpoint verifies before resolving the definition again with the identical context. `authorize()` on the definition gates both the initial render and every fetch. The route's middleware and path follow Lattice's group conventions: `config('lattice.trees.middleware', ['web', 'auth'])` and `config('lattice.trees.endpoint', 'lattice/trees/{tree}')`.

An `EloquentTreeSource` behind the endpoint automatically switches to per-level queries (`WHERE parent_id = ?` plus a scoped `EXISTS` probe for `hasChildren`) instead of loading the whole table. Inline `->nodes()` / `->source()` trees stay eager-only — without a registry key there is nothing to seal — so `->lazy()` on them throws.

Translations
------------

[](#translations)

The component's strings ship with inline English defaults. With [bambamboole/laravel-i18next](https://github.com/bambamboole/laravel-i18next) enabled and `@lattice-php/lattice` &gt;= 0.23, the plugin's `tree` namespace is loaded automatically and serves the bundled `en`/`de` translations (override them like any Laravel package translation).

Development
-----------

[](#development)

```
composer install
composer check   # pint --test, phpstan, pest
```

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/547137a6d80cad01ed1dd065b1c6af329d9a23a4134a895cff01e078cc155500?d=identicon)[bambamboole](/maintainers/bambamboole)

---

Top Contributors

[![bambamboole](https://avatars.githubusercontent.com/u/8823695?v=4)](https://github.com/bambamboole "bambamboole (18 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lattice-php-tree/health.svg)

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

PHPackages © 2026

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