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
Closure Table

Closure Table Laravel Package

franzose/closure-table

Closure table implementation for Laravel that turns flat tables into efficient hierarchical trees. Query ancestors and descendants in one call, move nodes without rebuilding the tree, and keep parent-child relationships fast, simple, and scalable.

View on GitHub
Deep Wiki
Context7

franzose/closure-table brings the closure table pattern to Laravel for efficient hierarchical data storage. It integrates with Eloquent models and records every ancestor–descendant path in a dedicated table, enabling fast tree queries without recursive database calls.

  • Eloquent model integration and migration support
  • Query ancestors, descendants, and direct children
  • Move nodes and subtrees while preserving paths
  • Depth, root, and leaf helpers
  • Works alongside existing Laravel models and queries
Frequently asked questions about Closure Table
What is the closure table pattern and how does franzose/closure-table implement it in Laravel?
The closure table pattern stores every ancestor-descendant pair, plus depth, in a separate table. franzose/closure-table layers that table over an existing adjacency-list parent_id column, so simple parent lookups stay cheap while ancestor and descendant queries become a single indexed join. In Laravel it ships Eloquent traits, a base node model, and Artisan migration generators. You get relationship-style accessors such as parent, children, ancestors, and descendants plus tree-mutating methods.
How do I install and configure franzose/closure-table in a Laravel app?
Install it with Composer, then generate and run the closure table migration using the package's Artisan command. Add the package trait to your model or extend its base node model, and keep the existing parent_id column on your entity table. For an existing tree, plan a backfill or rebuild step before relying on the closure rows.
Which Laravel and PHP versions are supported by franzose/closure-table?
The package's composer.json is the source of truth for framework and PHP constraints. The recent release date suggests active maintenance, but you should verify Laravel 11/12 and PHP 8.2+ support against the actual constraints and CHANGELOG before committing. Check the supported database engines too, since index and lock behavior differs between MySQL, PostgreSQL, and SQLite.
How do I fetch ancestors, descendants, and subtrees with franzose/closure-table?
Use the relationship-style accessors provided by the node model: parent and children for immediate neighbors, ancestors and descendants for the full closure paths, and subtree helpers for a node plus everything below it. These queries hit the closure table with an indexed join, which is the main performance benefit over recursive adjacency queries. Results are typically returned as Eloquent collections.
How do I move a node or make it a child or sibling of another node?
The package exposes tree-mutating methods such as make child of, make sibling of, and move. These operations rewrite multiple closure rows, so wrap them in database transactions and consider locking the affected subtree under concurrent writes. Avoid moving large subtrees frequently, because cost grows with subtree size times ancestor count.
Is there a rebuild or backfill command for an existing adjacency list parent_id tree?
Confirm whether the package ships a supported rebuild or backfill Artisan command for importing an existing parent_id tree. If it does not, write a one-off backfill script that inserts the self-referencing rows and all ancestor-descendant pairs. Validate it on a copy of production data and make it idempotent or safe to re-run.
Does franzose/closure-table support soft deletes, multi-tenancy, and UUID primary keys?
Treat these as integration checks rather than assumptions. Verify how the package scopes closure rows for soft deletes and multi-tenancy, and whether UUID or ULID primary keys are supported by the migration and query code. If your app uses non-integer keys or tenant scoping, test the generated schema and all move/delete paths thoroughly.
What are the performance and scale limits of using a closure table in Laravel?
Reads are the strong point: ancestor, descendant, and subtree lookups are indexed joins and stay fast on shallow to moderate trees. Writes are heavier because inserts, deletes, and moves touch multiple closure rows, scaling roughly with subtree size times ancestor count. Benchmark on realistic node counts and depth, and be cautious beyond depth 10 or millions of nodes.
Is franzose/closure-table safe for concurrent writes and production use?
For production, ensure every tree mutation goes through the package inside a transaction with appropriate locking. Raw SQL, bulk updates, seeders, or admin tools that bypass model events can silently corrupt the closure table, so run periodic integrity checks. Also note the single-maintainer risk: keep an exit plan, though the MIT license and portable schema limit lock-in.
How does franzose/closure-table compare to alternatives like nested sets or recursive CTEs?
Nested sets, such as kalnoy/nestedset, give fast reads but expensive writes and are awkward for frequent re-parenting. Recursive CTEs in PostgreSQL or MySQL 8 avoid a closure table but can be less portable and harder to index for deep trees. Materialized paths sit between the two. The closure table is a good fit for read-heavy Laravel hierarchies where moves are relatively rare.
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.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console