kalnoy/nestedset
Laravel Eloquent implementation of the Nested Set model for storing hierarchical data. Manage trees with fast reads: add, move, delete nodes, retrieve ancestors/descendants, build menus, and handle multiple roots with scoped trees, all via familiar model methods.
Architecture fit: Trait-based implementation aligns perfectly with Laravel's Eloquent architecture. Optimized for read-heavy hierarchical data (e.g., menus, categories) with O(1) subtree queries but O(n) write complexity for tree modifications. Supports Laravel 7-12 with PHP 8.0+ requirements.
Integration feasibility: High for modern Laravel projects. Composer dependencies explicitly cover Laravel 7-12 and PHP 8.0+. Migration helper (Schema::nestedSet()) simplifies schema setup.
Technical risk: O(n) write operations could bottleneck large trees (>10k nodes). Manual lft/rgt manipulation risks tree corruption. Dependents count of 0 despite 3.7k stars suggests limited enterprise adoption. PHP 8.4 compatibility fixed in v6.0.6 but requires strict version adherence.
Key questions: How does the package handle concurrent tree modifications? What's the performance profile of rebuildFromTree() for 50k+ node datasets? Are there known issues with soft-delete + scoping interactions? Does it support sharding for extremely large trees?
Stack fit: Native Eloquent integration via HasNestedSet trait. Works with existing Laravel models without major refactoring. Fully compatible with Laravel's query builder, scopes, and relationships.
Migration path: For new projects: install package → add trait → generate migration → seed data. For existing adjacency-list trees: write custom migration script to convert data using rebuildFromTree(). Prioritize testing with small datasets before full rollout.
Compatibility: Requires Laravel 7-12 and PHP 8.0+. Deprecated methods (e.g., appendTo) are replaced with appendToNode in v4.1+. Ensure legacy code updates during migration.
Sequencing: 1) Add package via Composer 2) Apply trait to target models 3) Run nestedSet migration 4) Implement scoping early if multi-tree support needed 5) Test critical operations (rebuild, move nodes) in isolation before production.
Maintenance: Actively maintained with recent PHP 8.4/Laravel 12 fixes. MIT license simplifies
How can I help you explore Laravel packages today?