efureev/laravel-trees
Laravel Trees adds nested-set tree support to Eloquent models, making it easy to build, query, move, and reorder hierarchical data like categories or menus with efficient ancestor/descendant operations and a simple API.
docs/Concepts.md), which is exactly the trade-off a PM needs surfaced before committing a schema.RangeCheck), a second root (RootCheck), and orphans (MissingParentCheck). This turns "is our production tree intact?" into a runnable audit rather than a manual SQL exercise — useful for on-call runbooks, pre/post-migration verification, and admin-facing data repair tooling.isDescendantOf() / isDirectChildOf() and parentsByModelId() now working on single trees, this supports bulk hierarchy imports, re-parenting scripts, and one-off data fixes with far less bespoke code to review.src/, plus a single composer gate command reproducing CI locally, reduces the internal cost of owning this dependency and shortens code review for contributions or forks.Caveat for the decision log: the migration surface is genuinely small — three internal-only signatures, the shape of HealthyChecker's return array, the argument order for the now-static Table::fromQuery(), and one exception import. Everything else is behaviour that was incorrect being corrected. That means the upgrade is cheap in engineering effort and expensive only in platform terms (PHP 8.5 availability).
Consider it when:
Look elsewhere when:
parent_id column and a scope is less machinery, and the package's own new documentation says as much.Adoption criteria to confirm before committing: PHP 8.5 on the target runtime and CI image, Laravel 13, a write profile that tolerates bounded-range updates, and a plan for running HealthyChecker against existing production data — including the new checks, which will surface gaps and orphans that the previous three-check suite reported as healthy.
For executives — one paragraph:
This release is a stabilisation milestone for the tree/hierarchy component our catalog, navigation, and permission structures depend on. It fixes a set of subtle data-corruption bugs — incorrect re-parenting on delete, bounds updated on the wrong database connection, integrity checks that miscounted defects — that would otherwise have surfaced as corrupted hierarchies and manual data repair. Test coverage roughly tripled and now exercises every line of the library, so the risk of regressions reaching production is materially lower. The one material cost is platform currency: the library now requires PHP 8.5. There is no functional reason to delay beyond that dependency, and the migration itself is a handful of small, documented edits.
For engineering leads:
The upgrade path is short and documented in
MigrationGuide.md. Four things change: three signatures only reachable from inside the package,HealthyChecker::check()now returns six entries instead of three,Table::fromQuery()is static and no longer picks up configuration applied before the call, and one exception import moves fromPhp\SupporttoFureev\Trees\Exceptions\InvalidConfigException(same name, same message — only theusestatement changes). Everything else is a correction to behaviour that was wrong: duplicate and wrong-parent checks now count nodes rather than pairs and triples, so a single defect no longer scores higher on a larger tree;ancestorsanddescendantsare ordered on every path including eager loading;shift()moves both bounds in one statement.Contracts\TreeModelnow describes every method the traits add, so code typed asModel&TreeModelpasses static analysis, and a test fails if the contract and traits drift again. Runcomposer gatelocally — PHPStan, PHPCS and PHPUnit in CI order, orgate:dockerif you'd rather not manage the toolchain. Note that the newRangeCheck,RootCheckandMissingParentCheckwill flag real defects in existing trees that the old checks passed; plan a health-check run against staging before rollout and treat any findings as genuine data issues, not false positives.
Headline for the roadmap review: low-migration-risk, high-integrity-value release; the only scheduling dependency is PHP 8.5 availability in the runtime and CI image.
How can I help you explore Laravel packages today?