Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Nestedset Laravel Package

aimeos/laravel-nestedset

Laravel nested set package for storing and querying hierarchical data as trees. Adds tree support to Eloquent models with fast ancestor, descendant, sibling, and depth queries via left/right indexes, plus simple APIs for moving nodes and rebuilding trees.

Deep Wiki
Context7

Product Decisions This Supports

Feature scoping: which hierarchy features are worth building. Nested sets answer "give me this subtree", "give me the ancestors for a breadcrumb", "count everything under this node" in a single indexed query rather than recursive application code. That makes a set of features cheap enough to put on the roadmap as one workstream rather than several:

  • Category / taxonomy navigation with depth-limited menus and breadcrumbs
  • Org units, team hierarchies, and reporting-line rollups
  • Nested permissions or feature-flag inheritance ("inherit from parent unless overridden")
  • Threaded comments or Q&A with subtree pagination and collapse/expand
  • CMS page trees, sitemap generation, and drag-and-drop menu reordering
  • "Filter by any node in this branch" on catalog or content listings — the hardest query to fake with parent_id alone

Build vs buy. The build alternative is a parent_id column plus recursive CTEs or application-level recursion. In MySQL 8 / Postgres that is genuinely viable and has zero dependency risk, but it costs you: recursive query builders, cycle protection, ordering logic, move operations, and a pile of tests you'd rather not own. This package is roughly the "buy" answer at near-zero price. The real decision is not build-vs-buy but which tree library — and whether to own an abstraction layer over it.

Sequencing and data model. Choosing a tree encoding is effectively a one-way door. Migrating a populated parent_id tree to nested sets (or back) later is a data migration plus a rewrite of every read path. So this decision gates schema design, and schema design gates everything downstream. Decide before the first migration ships, not after.

Risk posture on a low-signal dependency. 39 stars is a signal, not a verdict. The mitigating read: this appears to be a fork maintained inside the Aimeos e-commerce stack, so it likely gets fixed because a commercial product needs it — but its roadmap serves Aimeos, not you. Treat it as "adopt with an exit", and budget the thin abstraction layer (a TreeRepository interface, or at minimum confining tree calls to one service class) as part of the cost of adoption, not as gold-plating.

When to Consider This Package

Adopt when most of these hold:

  • Your stack is Laravel/Eloquent and hierarchy is a first-class domain concept, not an afterthought.
  • Read-heavy workload: subtree reads, ancestor lookups, and counts vastly outnumber structural edits.
  • Trees are moderate in size — thousands, not millions, of nodes per tree — and moves are admin-driven and infrequent.
  • You need ordering, depth, and subtree queries simultaneously; parent_id alone already feels painful in code review.
  • You want the nested-set semantics without writing and maintaining the move logic and its invariants (_lft/_rgt integrity, depth consistency, no cycles).
  • You're willing to pin a version, own the migration, and wrap the calls.

Look elsewhere when any of these hold:

  • High write churn on structure. Nested sets rewrite every node to the right of an insertion point. A tree that is reordered continuously (live drag-and-drop across many concurrent editors) will produce lock contention and row-update amplification that no amount of indexing fixes. Consider materialized paths or adjacency + recursive CTE.
  • Very large or very deep trees where a single move touches tens of thousands of rows.
  • Graph, not tree. Multiple parents, cross-links, DAGs — nested sets cannot express this. Closure table or an explicit edge model.
  • You need traversal-heavy ad-hoc querying — path predicates, ltree-style operators, or recursive reporting. Native ltree (Postgres) or recursive CTEs are stronger and dependency-free.
  • Procurement or compliance requires a supported dependency. No SLA, no security-response commitment, modest adoption. If a tree library outage is a P1 for you, that's a real cost.
  • The mainstream upstream is healthier. This is a fork of the widely used kalnoy/nestedset lineage; before committing, compare activity, issue response, Laravel version support, and open-CVE history between the two. A fork you don't need is pure downside.

Non-negotiables if you adopt: NOT NULL unique-ish constraints on the left/right columns, a migration/repair command to detect and fix corrupted trees, and tests that assert tree integrity after every move operation you expose in the UI.

How to Pitch It (Stakeholders)

To executives — one paragraph: "Hierarchical data — categories, org structure, menus, permissions — is needed by several roadmap items. We can buy that capability as a small open-source Laravel package instead of building it, which removes roughly a sprint of engineering and an ongoing maintenance tail from our plans. The package is free and small; our actual investment is a short integration and a thin internal wrapper so we are never locked in. Main caveat: it's a low-profile fork, so we pin the version, add integrity tests, and keep a documented exit path. Net: feature velocity now, contained risk, no vendor contract."

To engineering — the honest version:

  • It's a nested-set implementation for Eloquent: _lft/_rgt/depth/parent_id, with subtree, ancestor, sibling, and move APIs. Good fit for read-heavy trees.
  • The trade-off is explicit: fast subtree reads, expensive structural writes. Any UI that lets users reorder large branches needs a design conversation before it ships.
  • It's a fork with modest adoption. Vendor it behind an interface, pin the version, and diff against upstream before any major Laravel upgrade.
  • Deliverables we're committing to: schema migration, tree-integrity check command, tests covering every mutation path we expose, and one service class that is the only place that imports the package.
  • What we are explicitly not doing: using it as a general graph model, or as the backbone for high-frequency collaborative reordering.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
encore2/laravel-admin2
cboxdk/laravel-console-kit
shapecode/doctrine-dbal-datetimeutc
gilads-otiannoh254/inertia-protocol
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
adachsoft/cli-process-tester
adachsoft/changelog-linter
adachsoft/collection
adachsoft/php-code-style
adachsoft/api-version-bundle
cgv/localized-resource