korridor/laravel-has-many-merged
Adds a hasManyMerged relationship to Laravel Eloquent, letting you combine several hasMany relations across models into one query-backed collection with sorting, limits, and eager loading. Ideal for unified feeds, timelines, and activity lists.
collect()->merge()->sortBy() in controllers, or hand-written UNION SQL. Both work; both drift. This is a ~90-star, MIT-licensed, single-maintainer dependency with 0 public dependents — so approve it as a small utility, not a platform bet. The decision framework: pin the version, name a fork owner, and treat removal as a one-model refactor. That cheap reversibility is the whole argument for saying yes.with(), whereHas, withCount, withSum, pagination, ordering — so merged data flows through the existing ORM path rather than spawning a parallel data-access layer. PM framing: it reduces the chance that a dashboard ships late because two teams built incompatible merge helpers.hasMany only; not real-time, not write-path, not belongsToMany/hasOne/hasManyThrough, not field-level fusion. Any merged set expected to exceed roughly 10K rows needs database-side filtering and pagination, enforced in review. And measure latency on production-shaped data before this backs an endpoint with an SLO.hasMany relations across controllers, API resources, or reporting queries.whereHas across those relations as a single association — the exact shape this package provides.toSql() answers "does it work" in minutes.belongsToMany/hasOne/hasManyThrough — the scope is hasMany only.hasMany relations, producing duplicated logic, inconsistent ordering and deduplication, and N+1 risk. Solution: a HasManyMerged relation that behaves like a native relation — with(), pagination, aggregates, whereHas, custom merge logic — with strict types, PHPStan generics, and test coverage for aggregates going back to 0.0.3. Drop-in, no service provider, no schema change. Risks: hasMany-only scope, in-memory merge cost at scale, low external adoption. Mitigations: pin the version, spike with production-shaped data, require DB-level filters and pagination for large sets, and keep a localized fallback to native queries."How can I help you explore Laravel packages today?