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

Tree Laravel Package

nicmart/tree

A flexible PHP tree data structure with a fluent builder API. Create nodes with any value, add or remove children, manage parents automatically, and build hierarchies easily for menus, categories, and nested data.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature scoping for hierarchy-heavy workflows. Use this package when a feature needs to model, traverse, and reason about parent/child relationships in memory: category and navigation menus, org charts, permission/resource hierarchies, comment threads, decision/workflow trees, dependency or bill-of-materials structures, and breadcrumb generation.
  • Build vs. buy. The package replaces a small but error-prone custom layer of recursive array walking, ancestor lookup, depth/height calculation, and traversal ordering. At MIT license and a small API surface, the “buy” cost is near zero, and the “build” alternative is only justified if requirements are highly specialized.
  • Roadmap input for hierarchy features. Its visitors (pre-order, post-order, yield/leaves) and node metrics (size, depth, height, root, ancestors, neighbors) map directly to user-facing capabilities such as subtree export, ordered rendering, “show only leaf categories,” dependency resolution, and scoped permission checks.
  • Architecture and dependency decisions. Because it is an in-memory data structure rather than a persistence layer, it supports decisions about where hierarchy logic lives: domain/service layer versus database schema. That distinction matters for Laravel applications that already use Eloquent relationships, nested sets, or adjacency lists.
  • Risk and maintenance planning. With 574 stars, zero dependents in the observed data, and a 0.x version line, it is a low-cost, low-blast-radius dependency. The PM decision is less “is this strategic?” and more “does the team want to own a small tree utility or delegate it?”

When to Consider This Package

Consider adoption when:

  • The application needs in-memory tree construction and traversal rather than database-backed hierarchy querying.
  • The domain naturally forms a strict tree (each node has one parent), not a graph, DAG, or many-to-many hierarchy.
  • The team wants fluent tree building for fixtures, seed data, configuration-driven menus, or generated organizational structures.
  • Features need ancestor/descendant traversal, leaf detection, depth/height, subtree size, or ordered visitors without writing recursive utilities.
  • The stack is PHP 8.x/Laravel and the MIT license is acceptable.
  • The dependency can be wrapped behind an internal interface, keeping the option to swap implementations later.

Look elsewhere when:

  • Hierarchy must be persisted and queried efficiently in a relational database. Use a nested-set or adjacency-list package (for example, Laravel-oriented nested-set/adjacency-list solutions) or recursive CTEs instead.
  • Requirements include graphs, multiple parents, cross-links, or DAG semantics. This package models a strict tree.
  • The team needs a stable 1.x API contract. The package is still on a 0.x line, so minor releases may introduce breaking changes; pin versions and isolate usage.
  • Ecosystem validation is a hard procurement criterion. Zero observed dependents and a narrow feature set mean limited peer evidence.
  • Performance requirements involve very large trees or high-frequency mutations; an in-memory PHP object graph may not be the right fit without benchmarking.
  • The product needs authorization-aware, database-integrated hierarchy behavior out of the box. This package provides structure and traversal, not persistence, caching, or Laravel integration.

How to Pitch It (Stakeholders)

For executives: This is a small, MIT-licensed PHP utility that gives our teams a reliable way to represent and traverse hierarchical data — menus, categories, org structures, permission trees — without building bespoke recursive code. It is cheap to adopt, easy to remove, and does not add a platform or vendor commitment. The main caveat is that it is an in-memory structure, not a database hierarchy solution, and it is still pre-1.0, so we should pin the version and keep it behind our own interface.

For engineering: The package provides a NodeInterface/Node implementation with parent, child, ancestor, neighbor, depth, height, size, root, and leaf operations, plus a fluent NodeBuilder and pre-order/post-order/yield visitors. It supports PHP 8.4, is MIT-licensed, and has CI, coverage, changelog, and release signals. Adopt it for in-memory tree composition and traversal; do not use it as a replacement for Eloquent-backed nested sets or adjacency lists. Wrap it in a small internal adapter so a future swap is a contained change, and pin the 0.x version to avoid surprise breaks.

Recommendation: Approve for narrow, in-memory hierarchy use cases where the alternative is custom recursive code. Do not standardize on it as the organization’s hierarchy persistence layer.

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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log