paxha/laravel-recursive-relationships
Laravel package for defining and working with recursive relationships in Eloquent models—query parent-child hierarchies, trees, and nested structures with ease. (Approx 160 chars - need closer to 300) Let me expand to ~300 chars: Laravel package for defining and querying recursive relationships in E...
Architecture fit. The package extends Eloquent with a recursive relationship trait that resolves hierarchy traversal (parent/child chains, org charts, category trees, threaded comments) via SQL common table expressions (WITH RECURSIVE) rather than iterative PHP loops. For a Laravel codebase already modeling self-referential adjacency lists (parent_id), this is a natural fit at the model layer and avoids the classic anti-pattern of N+1 recursive hydration. It is a thin, single-purpose utility — not a framework, not a service — which is the right scope for a dependency of this size.
Integration feasibility. Integration is low-ceremony: a trait on the model plus configuration of the foreign key and local key. The real feasibility gate is the database engine, not Laravel itself. Recursive CTEs require MySQL 8.0+, PostgreSQL 8.4+, SQLite 3.8.3+, or SQL Server. Any footprint still on MySQL 5.7 — common in inherited or legacy estates — cannot use this package at all, and that is a hard blocker rather than a configuration issue.
Technical risk. High, and concentrated in three areas:
Key questions.
WITH RECURSIVE assumed, or is there a fallback?Stack fit. Suitable only where the persistence layer is MySQL 8+ or PostgreSQL and the Laravel version is pinned to something the package was built against. Treat it as a candidate for a bounded spike, not a default dependency.
Migration path. Do not adopt via Composer as an ongoing dependency. The pragmatic path is to fork the repository into the organization's namespace (or vendor the trait directly into app/Support), pin it, and own it. MIT licensing makes this straightforward and legally clean. This converts an unmaintained third-party risk into a small, auditable piece of first-party code — roughly a few hundred lines — that the team can patch against framework upgrades.
Compatibility. Two axes must be cleared before any code is written:
Sequencing.
Maintenance. This is the dominant cost. With no active upstream, every Laravel major upgrade becomes a first-party migration task. Budget for an owner — a named engineer or team — and a review cadence tied to framework upgrades. The code surface is small enough that this is manageable; the risk is that it is forgotten until a PHP deprecation breaks it in production.
Support. Community-only, effectively none. No vendor, no SLA, no recent issue triage. Internal documentation of the fork's behavior and constraints is mandatory. Security posture is low-risk given the package issues read queries, but the raw SQL surface should be audited for interpolation before adoption.
Scaling. Recursive CTEs are the right tool performance-wise: one round trip instead of N. But the characteristics are non-linear with depth. Deep hierarchies, wide fan-out, and missing indexes on the parent column will produce slow plans. Cycle-containing data will either loop until a limit or exhaust resources. Memory pressure comes from hydrating large flat result sets into models — consider returning raw rows or chunking for very large trees. Caching resolved trees (with invalidation on write) is likely necessary at scale.
Failure modes.
Ramp-up. Low for engineers comfortable with SQL; the trait usage is a few lines. The conceptual load is understanding what the CTE returns and how it differs from a standard relation — worth a short internal write-up and a worked example in the codebase. Onboarding cost is trivial; the organizational cost is the ownership commitment, which must be made explicit before adoption.
Recommendation. Do not adopt as a live dependency. Fork it, harden it with depth and cycle guards, validate against the real Laravel/PHP/database matrix, and roll it out to a single bounded model. If the spike surfaces framework incompatibility that takes more than a day to resolve, build the equivalent in-house — the implementation is small and the team will own it either way.
How can I help you explore Laravel packages today?