A Laravel package implementing the Closure Table pattern with adjacency lists for efficient hierarchical data storage and querying.
ClosureTable is a Laravel package that implements the Closure Table database design pattern for managing hierarchical data. It allows developers to store, query, and manipulate tree-like structures (such as categories, menus, or nested comments) efficiently within Laravel applications. The package combines the Closure Table pattern with adjacency lists to optimize both complex hierarchical queries and simple parent-child lookups.
Laravel developers who need to manage hierarchical data in their applications, such as those building content management systems, e-commerce platforms with nested categories, or any application requiring tree-like data structures.
Developers choose ClosureTable because it provides a battle-tested, Laravel-native solution for hierarchical data that is both performant and easy to use. It offers a comprehensive set of query scopes and methods out of the box, eliminating the need to write complex recursive queries or implement custom tree logic.
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offers a wide range of built-in Eloquent scopes for ancestors, descendants, siblings, and more, as listed in the Scopes section, reducing the need for custom recursive queries.
Combines closure table for deep hierarchical queries with adjacency list (parent_id) for immediate parent/child lookups, balancing flexibility and speed as described in the philosophy.
Provides methods for moving nodes, creating subtrees, and deleting subtrees, such as moveTo() and deleteSubtree(), simplifying complex tree operations without manual SQL.
Includes additional collection methods like toTree() and getNeighbors(), making it easier to work with hierarchical data in Laravel's collection pipeline.
The README highlights deprecated methods since ClosureTable 6, such as replacing getAncestorsTree() with toTree(), which can cause migration headaches and code refactoring.
Requires specific columns like parent_id, position, ancestor, descendant, and depth, limiting customization and forcing a particular table structure that might not fit all use cases.
Involves running artisan commands and understanding the closure table pattern, which can be daunting for developers new to hierarchical data management in databases.
Maintaining both adjacency list and closure table entries increases write operations and storage, potentially slowing down inserts and updates in large, dynamic trees.