Weave Code
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 Composite Relations Laravel Package

reedware/laravel-composite-relations

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Schema Flexibility: Enables modeling of complex database schemas with composite foreign keys (e.g., multi-column relationships in legacy systems or normalized designs). Supports use cases where traditional single-key relationships fall short, such as:
    • Junction tables with composite keys (e.g., user_id + permission_id).
    • Multi-dimensional relationships (e.g., Order linked to both Customer and Store via customer_id + store_id).
    • Legacy system integrations where composite keys are mandatory.
  • Developer Experience: Reduces boilerplate and technical debt by providing Eloquent-like syntax for composite relations, avoiding custom query logic or raw SQL. Aligns with Laravel’s declarative approach, improving maintainability and onboarding.
  • Roadmap Prioritization: Justifies investment in features requiring composite keys, such as:
    • Multi-tenancy architectures with tenant-specific relationships.
    • Hierarchical or tree-like structures with composite parent-child relationships.
    • Financial or inventory systems with multi-column foreign keys (e.g., product_id + variant_id).
  • Build vs. Buy: Eliminates the need to build custom solutions for composite relations, saving development time and reducing long-term maintenance risks. The MIT license and active updates (as of 2025) further reduce adoption barriers.
  • Performance Optimization: Supports efficient querying of composite relations, including eager loading and whereHas clauses, which is critical for scalable applications.

When to Consider This Package

  • Adopt When:
    • Your application’s database schema requires composite foreign keys (e.g., legacy systems, normalized designs, or multi-column primary keys).
    • You need to model complex relationships that cannot be expressed with single-key foreign keys (e.g., relationships involving three or more tables with composite keys).
    • Your team prioritizes developer productivity over raw SQL flexibility, and you want to avoid writing custom query logic for composite relations.
    • You are using Laravel 11 or 12 and need a maintained, well-documented solution for composite relations.
    • Your use case involves eager loading or existence queries (e.g., whereHas) for composite relations, which this package explicitly supports.
    • You are working with multi-tenancy, hierarchical data, or financial systems where composite keys are common.
  • Look Elsewhere If:
    • Your application’s relationships are simple and can be modeled with single-key foreign keys (native Eloquent is sufficient).
    • You require many-to-many composite relations (this package does not support belongsToMany with composite keys).
    • Your team lacks PHP/Laravel expertise to debug or extend the package, as composite relations introduce additional complexity.
    • You need active, frequent updates (last release was in 2025; monitor for future updates or forks if this is critical).
    • Your use case involves polymorphic composite relations (not supported by this package).
    • You are using Laravel versions outside 11/12 (e.g., 10 or below), as support for older versions has been dropped.
    • You prefer raw SQL or query builder flexibility over Eloquent’s declarative syntax for composite relations.

How to Pitch It (Stakeholders)

For Executives: "This package allows our Laravel backend to handle complex database relationships—like linking orders to both customers and stores—using clean, Eloquent-style code instead of manual SQL. It’s a drop-in solution for legacy systems or multi-key schemas, reducing development time and technical debt. With an MIT license, minimal maintenance requirements, and compatibility with Laravel 11/12, it’s a low-risk way to unlock flexibility for projects where relational complexity is a bottleneck. For example, it could simplify multi-tenancy, hierarchical data, or financial systems where composite keys are common. The package is already adopted by 20+ projects, indicating its reliability."

For Engineering: *"Composite relations in Laravel are a common pain point—this package fills that gap by supporting BelongsTo, HasOne, and HasMany with multi-column foreign keys. Here’s why it’s worth adopting:

  • No raw SQL: Keep Eloquent’s fluent syntax (e.g., $order->customerStore instead of custom queries).
  • Legacy-friendly: Works seamlessly with databases using composite keys (e.g., user_id + role_id).
  • Performance: Optimized queries under the hood, with support for eager loading and whereHas.
  • Low friction: 5-minute setup, MIT license, and Laravel 11/12 compatible. Tradeoffs:
  • Doesn’t cover belongsToMany or polymorphic composite relations (but covers 80% of use cases).
  • Requires validation of your specific use case (e.g., does it fit the supported relation types?).
  • Last release was in 2025, so monitor for updates if this is critical to your roadmap. Recommendation: If you’re hitting limits with native Eloquent for composite relations, this is a high-leverage solution to evaluate."*

For Data/Database Teams: *"This package provides a clean, Eloquent-based way to handle composite foreign keys without sacrificing query performance or maintainability. It’s particularly useful for:

  • Legacy migrations: Integrating with databases that use composite keys (e.g., user_id + tenant_id).
  • Complex joins: Simplifying queries that involve multiple foreign keys (e.g., WHERE (user_id = ? AND tenant_id = ?)).
  • Consistency: Standardizing how composite relations are defined across the codebase. Considerations:
  • Ensure your schema truly requires composite keys (can you normalize or use intermediate tables instead?).
  • Test thoroughly with edge cases (e.g., NULL values, duplicate keys).
  • Document composite relation usage clearly for future developers."*
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity