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

Eager Load Pivot Relations Laravel Package

ajcastro/eager-load-pivot-relations

Laravel package that eager loads relations defined on pivot models in many-to-many relationships, eliminating N+1 queries when accessing nested pivot data. Use familiar Eloquent syntax to keep role_user, post_tag, and similar pivot records fast and clean. Drop-in trait and builder methods make setup...

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • ajcastro/eager-load-pivot-relations is a narrow, single-purpose Eloquent extension for Laravel: it lets you eager load relations hanging off BelongsToMany pivot models (e.g. with('roles.pivot.permissions')) rather than triggering N+1 queries on pivot-attached data.
  • Fit is high if the domain genuinely models attributes/relations on the pivot (role assignment metadata, membership audit fields, order-line options). If pivots are pure join tables, this package adds dependency surface for no benefit.
  • It is a library-level concern, not an architectural one: it does not impose structure, service providers of its own beyond registration, or repository patterns. Low coupling, easy to reverse.

Integration feasibility

  • Composer-installable, Laravel package conventions (service provider + trait/macro on the query builder or relation). Integration is typically a use statement on affected models plus updating with() calls.
  • Realistic effort: half a day for a spike in a staging branch, 1–3 days to convert existing call sites and verify query counts on high-traffic endpoints.
  • Requires a test harness that asserts query counts (Laravel's DB::listen / assertQueryCount), otherwise the benefit is unverifiable.

Technical risk

  • Pre-1.0 API instability. v0.3.0 is a 0.x release; semver permits breaking changes in minor bumps. Every release must be treated as potentially breaking until 1.0.
  • Release hygiene risk. The v0.3.0 notes are a bare link to PR #11 with no changelog, no migration notes, no BC statement. We cannot determine from the release itself whether method signatures, trait names, or supported Laravel versions changed. This is the single largest unknown in this review.
  • Maintenance concentration. Single-author package; no evident corporate backing. Bus-factor risk is material.
  • Framework-internals coupling. Eager-loading internals (Relation, Builder::eagerLoadRelations) change between Laravel majors, so the package is structurally exposed to Laravel upgrade cycles.

Key questions

  1. What exactly changed in PR #11 — new capability, bug fix, or breaking signature change? Is there a diff we can review before upgrading?
  2. Which Laravel and PHP versions does v0.3.0 declare support for, and does that match our current runtime?
  3. Is there a CHANGELOG or tagged release history we can rely on, or must we diff tags ourselves?
  4. Does the package support load()/loadMissing() on already-hydrated models, or only with() at query time? This drives how much call-site churn we face.
  5. Are there tests in the repo covering pivot relation variants (morph-pivot, custom pivot models, nested pivot)? What is CI status?
  6. What is our exit cost — could we vendor a ~40-line trait if the package is abandoned?

Integration Approach

Stack fit

  • Requires Laravel (Eloquent) and PHP versions per composer.json; confirm against our pinned framework version before committing. Packages of this kind typically track the two most recent Laravel majors — verify, don't assume.
  • Fits an existing Eloquent-centric codebase with no additional infrastructure. No queue, cache, or config dependencies. No published config file expected.

Migration path

  • Introduce behind a feature branch, not a big-bang refactor. Add the dependency, apply the trait/macro to one or two models, and convert a single high-value read path.
  • Keep existing call sites working during migration — the package should be additive; if it is not (i.e. it alters default eager-load behaviour globally), escalate as a much higher-risk integration and prefer an opt-in trait.
  • Rollback is a composer remove plus reverting use statements; ensure no other code depends on package-specific APIs so rollback stays cheap.

Compatibility

  • v0.3.0 sits mid-0.x; pin exactly ("0.3.0", not ^0.3) and upgrade deliberately after reading the diff.
  • Check interaction with any existing Eloquent extensions (e.g. staudenmeir/eloquent-eager-limit, spatie/laravel-query-builder, custom Builder macros). Two packages both hooking eagerLoadRelations is a classic silent-conflict source.
  • Verify behaviour under Laravel Octane if used — static/macro registration must be idempotent.

Sequencing

  1. Confirm PR #11 contents and composer.json constraints against our runtime; request a changelog from the maintainer if none exists.
  2. Spike: install in a scratch branch, add a query-count test proving N+1 elimination on one real endpoint.
  3. Review the diff and pin the version; add a composer.json inline comment/ADR noting the pin rationale.
  4. Convert call sites in priority order (highest query-count offenders first), each behind a query-count regression test.
  5. Only after 1.0 or ~3 months of clean operation, consider loosening the pin.

Operational Impact

Maintenance

  • Low ongoing code maintenance, moderate dependency-watch burden. Budget a recurring review at each Laravel major upgrade to confirm the package still works or is replaceable.
  • Because it is 0.x with sparse release notes, treat every bump as requiring a diff review — that is real, recurring TPM-visible cost, not zero.
  • Mitigation: keep usage confined behind a small number of models/traits so the blast radius of an abandonment event is bounded and the escape hatch (vendoring) stays trivial.

Support

  • No commercial support. Upstream is GitHub issues/PRs from a single maintainer; response times unknown and unbounded.
  • Internal ownership must be assigned explicitly — a named engineer responsible for dependency health. Without that, this becomes an orphaned dependency.
  • Escalation path is: upstream issue → vendor the ~small trait ourselves. Document that path in the ADR so on-call is not improvising at 2am.

Scaling

  • Primarily a performance lever: replacing N+1 pivot queries with a bounded number of eager-load queries reduces DB round-trips, which improves latency and connection-pool pressure under load.
  • Risk at scale is query size, not query count: eager loading pivots over large result sets can produce large IN (...) clauses. Validate on production-shaped cardinality, not fixtures.
  • No runtime footprint concerns — no extra processes, no added infrastructure.

Failure modes

  • Silent behaviour change on minor bump (most likely): post-deploy, eager loads stop hydrating pivot relations, or hydrate differently, and code reads null where data previously existed. Detect via feature tests asserting pivot payload shape, not just status codes.
  • Package abandoned / Laravel major incompatibility: eager loading throws or silently degrades after a framework upgrade. Detect via CI running the full suite against the target Laravel version before the upgrade lands.
  • Conflict with another Eloquent extension: nondeterministic eager-load results. Detect via integration tests on models using both packages.
  • Unbounded IN clause on large datasets: slow queries / memory spikes. Detect via query-time monitoring and load tests.
  • Rollback is cheap in all cases (revert use statements + composer remove), which is why the opt-in, narrow-footprint integration is worth insisting on.

Ramp-up

  • Very shallow: any Laravel developer understands with(); the only new concept is that pivot relations are addressable. Estimate under an hour of onboarding, best delivered as a short ADR plus one exemplar call site.
  • The real ramp-up is organisational: teaching the team when to reach for this versus a proper intermediate model. If pivot relations are becoming load-bearing domain concepts, the better long-term answer may be promoting the pivot to a first-class model — note that as an explicit architectural alternative in the ADR so this dependency doesn't become the default answer by inertia.

Recommendation pending PR #11 review: adopt, narrowly scoped and exactly pinned, contingent on confirming (a) no breaking changes in v0.3.0 and (b) declared compatibility with our Laravel/PHP versions. If PR #11 turns out to be a breaking change or the diff is unreviewable, defer and vendor the minimal implementation instead.

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.
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
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource