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 Has Many Merged Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature sequencing for "single list" experiences. The package answers one product question cheaply: does the user expect one consolidated list, or separate tabs/endpoints? Any roadmap item shaped like a unified timeline, activity feed, transaction history, or admin dashboard is a candidate; items requiring field-level derivation across tables (an "effective price," a computed status) are not. Draw that line explicitly so scope conversations happen before sprint planning, not after an engineer hits the wall.
  • Build vs. buy at utility scale. The build alternative is scattered 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.
  • De-risking delivery of data-rich surfaces. It preserves Eloquent ergonomics — 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.
  • Consistency as a user-visible quality bar. The most common defect in hand-rolled merges isn't a crash — it's two screens showing the same records in different orders or counts. Standardizing merge logic converts a recurring class of "why don't these numbers match?" bugs into a solved problem. That's a metric you can defend at review (defect reduction), as opposed to "hours saved," which is not.
  • Representative use cases to scope against. E-commerce order/product histories (products + variants + inventory), SaaS activity timelines (activity + notifications + collaborations), support views (tickets + messages + notes), analytics summaries (events + metrics + logs), and legacy consolidation where multiple source tables share one related model.
  • Guardrails to write into the product brief, not a wiki. Query-time merging of 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.

When to Consider This Package

  • Adopt when:
    • The team is already writing merge logic more than once or twice for multiple hasMany relations across controllers, API resources, or reporting queries.
    • A product requirement needs to eager-load, paginate, count, or whereHas across those relations as a single association — the exact shape this package provides.
    • Merge needs are moderate: consistent ordering, simple deduplication, standard constraints.
    • You're on Laravel 10–12 / PHP 8.1–8.3 with a team fluent in Eloquent.
    • You want a reversible win: no service provider, no config, no schema change, no backfill, no migration. A spike with toSql() answers "does it work" in minutes.
    • You can pin the version and assign a named fork owner as the fallback. Unnamed contingencies don't happen.
  • Look elsewhere if:
    • Relationships are deeply nested or involve belongsToMany/hasOne/hasManyThrough — the scope is hasMany only.
    • You need real-time, event-driven, or write-path merging; this is query-time only.
    • Datasets are very large without pagination or DB-side filtering — benchmark memory and latency first, and assume you'll need both.
    • You need field-level merging across tables; a custom accessor or explicit query is clearer and cheaper.
    • The merge is genuinely one-off; a small internal helper costs less than a dependency and a review cycle.
    • Your org has a policy against single-maintainer dependencies or requires strong third-party validation — fork, inline, or build a narrow macro instead.
    • You're not on Laravel/Eloquent.

How to Pitch It (Stakeholders)

  • Executives: "This is a small MIT-licensed Laravel utility that lets one model expose several one-to-many relationships as a single, consistently ordered relationship. It reduces custom merge code behind unified timelines, dashboards, and APIs — which means faster delivery and fewer 'the numbers don't match' defects. Honest caveats: community adoption is low, it's maintained primarily by one author, and its scope is deliberately narrow. So we're proposing a prototype on a non-critical, read-only feature, with version pinning and a named fork owner. Upside is faster delivery of data-rich features; downside is bounded because removal is a localized refactor with no data migration."
  • Engineering: "Problem: we hand-roll merges of 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."
  • Product/Design: "We can ship richer unified views — customer timelines, admin dashboards, multi-source feeds — with fewer loading states and simpler APIs because related records merge at the query layer instead of in the UI. That buys UX consistency and speed, provided we keep merged sets paginated and avoid it where relationships are deeply nested or where we need a single derived value across tables. Those cases stay custom work, and we should plan for them."
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.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log