staudenmeir/laravel-merged-relations
Merge multiple Laravel Eloquent relations into a single relation that can be queried and eager loaded as one. Combine hasMany, belongsToMany, and morph relations into a unified result set, simplifying complex relationship handling in your models.
activities table, dual-writes, backfill, reconciliation jobs) into a contained feature build. That is the core decision this package unlocks: ship the user-facing surface now, defer the denormalization question on your terms.UNION query-builder code that must independently re-implement eager loading, withCount, whereHas, and pagination semantics — a reliable source of subtly wrong results and quiet performance regressions. This is a narrow, single-purpose dependency (one trait, standard Eloquent relations) that typically displaces hundreds of lines of fragile custom query code. Default position: adopt, wrapped behind an internal interface. The 185 stars reflect a specialist tool rather than a weak one — the maintainer is a recognized name in the Laravel ecosystem, and this sits in a family of well-regarded Eloquent extensions.Adopt when:
withCount, existence checks, nested merging) so existing policies, scopes, and query patterns keep working unchanged.Look elsewhere when:
Upgrade note for v1.11: constraint-widening patch only. Confirm composer.json allows v1.11, verify the PHP floor implied by Laravel 13 against your runtime images, and run merged-relation integration tests on the upgrade branch. The package sits close to Eloquent internals, so it is in the blast radius of every Laravel major — put it on the framework-upgrade checklist so the next bump is anticipated rather than discovered. (Also confirm the rest of the dependency tree is Laravel 13-ready; the package being ready does not make the stack ready.)
For executives: This is a small, focused library that lets us ship "see everything in one place" experiences — unified feeds, cross-type moderation queues, account-wide activity views — without a risky data migration or a new denormalized table. It converts what looks like a multi-week schema-and-backfill project into a contained feature build, and it protects the roadmap from an expensive bet on denormalization we may not need yet. The v1.11 release is a pure Laravel 13 compatibility update, signaling active maintenance and removing a potential blocker from our framework upgrade. The residual risk is dependency concentration on a single maintainer, which we contain by isolating the package behind an internal interface so it can be replaced without touching product code. Cost of adoption is roughly a one-day spike plus tests — not a program of work.
For engineering: One trait, standard Eloquent relations. Merged relations support where, orderBy, paginate, eager loading, and withCount, so existing query patterns and authorization policies keep working unchanged. No migrations, no published config, no service bindings — opt-in per model. v1.11 adds Laravel 13 support with no API changes and no deprecations, making it a low-risk bump; the only action is validating the Composer constraint and running per-relation integration tests against Laravel 13. Recommended guardrails: wrap each merged relation in a named query object or repository so the package stays an implementation detail of the read layer rather than a public API of the domain; keep constituent relations clean and independently usable, with all filtering in one place; add tests asserting row-level correctness, ordering, and pagination boundaries — silently plausible-but-wrong SQL is the failure mode to guard against; capture EXPLAIN plans on production-sized data and watch for N+1s and query-plan regressions on high-traffic paths; pin the minor version; and document why each merged relation exists and what it replaced, or a future maintainer won't know whether it's safe to delete.
How can I help you explore Laravel packages today?