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

Laravel Recursive Relationships Laravel Package

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...

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Maintenance risk. Last release December 2020, 27 stars, 0 dependents, effectively a single-maintainer package. It predates Laravel 9, 10, 11, and 12, and predates PHP 8.1+. Compatibility with current framework internals (particularly Eloquent's relationship and query-builder contracts) is unverified and likely to have drifted.
  • Correctness risk. Recursive CTEs invite cycle-induced infinite loops and unbounded depth. Whether the package enforces a depth guard or cycle detection is the single most important thing to verify in a spike.
  • Hydration semantics risk. Recursive results do not map cleanly onto Eloquent's eager-loading and collection contracts. How depth, ordering, and model identity are returned determines whether downstream code can consume the relationship like a normal one.

Key questions.

  1. Does it support Laravel 10/11/12 and PHP 8.2+, or does it require a fork?
  2. Which database drivers are actually exercised — is WITH RECURSIVE assumed, or is there a fallback?
  3. Is there depth limiting and cycle protection, and are they configurable?
  4. What is returned — a flat collection with a depth column, a nested tree, or hydrated relations — and is it consistent with Eloquent conventions?
  5. Are there tests, and do they run against multiple engines and Laravel versions?
  6. Is there any security exposure (raw SQL interpolation of keys or table names)?

Integration Approach

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:

  • Framework/PHP: verify against the target Laravel and PHP versions in a throwaway branch. Expect to fix at least minor breakage given the 2020 vintage.
  • Database: confirm the production engine version. If MySQL 5.7 is anywhere in the estate — including staging, CI, or a DR replica — the package is disqualified for those environments and the team needs a consistent alternative (application-level recursion with memoization, or a materialized path / nested set schema).

Sequencing.

  1. Spike (1–2 days). Fork, run the existing test suite, then add a test against the target Laravel/PHP/database matrix. Instrument query counts and execution plans.
  2. Benchmark. Compare against the current implementation on a realistic tree (depth 8–10, tens of thousands of nodes). Confirm the CTE is actually faster than iterative loading and that the index on the parent key is used.
  3. Harden. Add depth cap, cycle detection, and a guard that fails loudly on unsupported drivers.
  4. Adopt narrowly. Apply to one model in one bounded context; observe in production.
  5. Generalize. Only after the narrow rollout proves stable, extend to other hierarchical models.

Operational Impact

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.

  • Hard failure on MySQL 5.7 or any non-CTE engine.
  • Infinite recursion / query timeout from cyclic or corrupt parent references.
  • Silent breakage on Laravel or PHP upgrade due to internal contract drift.
  • Divergent behavior across engines (ordering of recursive results is not guaranteed by SQL standard; do not rely on it without an explicit sort).
  • Inconsistent hydration causing subtle bugs in code that assumes a normal Eloquent relation.

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.

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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
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