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 Extended Relationships Laravel Package

mr-punyapal/laravel-extended-relationships

Adds efficient, extended Eloquent relationship helpers for Laravel models to cut queries, boost performance, and reduce duplicate code. Includes a HasExtendedRelationships trait and custom relations like belongsToManyKeys. Compatible with Laravel 11–13 and PHP 8.2+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization for High-Traffic Features:

    • Reduces N+1 queries in audit logs, user activity tracking, or hierarchical data (e.g., SaaS admin panels, e-commerce order histories). Justifies inclusion in performance-critical roadmap items (e.g., "Reduce API response time by 40%").
    • Enables single-query access to multiple related models (e.g., post->auditors->creator, post->auditors->updater) without manual query optimization.
  • Developer Efficiency for Complex Relationships:

    • Build vs. Buy Decision: Replaces custom relationship logic (e.g., hasManyThrough chains or raw SQL) for patterns like:
      • Audit trails (belongsToManyKeys for created_by, updated_by).
      • Tagging systems (hasManyArrayColumn for JSON arrays).
      • Legacy migrations (belongsToArrayColumn for string/ID arrays).
    • Saves 3–7 hours per feature for teams with limited backend resources, aligning with velocity-focused sprints.
  • Scalability for Data-Heavy Features:

    • Supports future-proofing for:
      • Multi-tenant analytics (e.g., tenant->users->activity).
      • Nested comment threads (e.g., post->comments->replies->author).
    • Integrates with Laravel Boost for real-time IDE guidance, reducing onboarding time for junior devs.
  • Cost Reduction for Legacy Systems:

    • Eliminates need for custom pivot tables or stored procedures for simple many-to-many relationships (e.g., replacing posts_tags table with posts->tags array column).
    • MIT License reduces legal risk compared to proprietary alternatives.
  • Use Cases with High ROI:

    • Audit Logs: Consolidate created_by, updated_by, deleted_by into one belongsToManyKeys relationship.
    • Tagging/Metadata: Use hasManyArrayColumn for lightweight many-to-many (e.g., Article::tags as JSON).
    • Reporting: Pre-load related data for batch exports (e.g., User::with('audited.created')->get()).
    • Legacy Integrations: Handle string/ID arrays in older databases via belongsToArrayColumn.

When to Consider This Package

  • Adopt When:

    • Your application exceeds 50+ queries per request (visible in Laravel Telescope, Blackfire, or New Relic).
    • You repeatedly implement custom relationship logic (e.g., manual hasManyThrough or raw SQL for audit trails).
    • Your team lacks dedicated backend resources to optimize queries but needs scalable solutions.
    • You’re migrating from legacy systems with non-standard data structures (e.g., JSON arrays, string IDs).
    • Your roadmap includes data-heavy features (e.g., analytics, activity feeds) where query efficiency is critical.
  • Look Elsewhere When:

    • Your relationships are simple and already optimized (e.g., basic hasOne/belongsTo with eager loading).
    • You require advanced query customization (e.g., raw SQL, complex joins) that this package doesn’t support.
    • Your team prefers full control over query generation (e.g., for audit logging compliance).
    • You’re using Laravel <11 or PHP <8.2, as the package drops support for older versions.
    • Your use case involves real-time syncing (e.g., WebSockets) where query efficiency is less critical than latency.

How to Pitch It (Stakeholders)

For Executives: "This package cuts database queries by 30–50% for common patterns like audit logs and tagging systems, directly improving API response times and scalability. For example, replacing manual created_by/updated_by columns with a single belongsToManyKeys relationship reduces our query count from 12 to 1 per request—saving server costs and accelerating feature delivery. The MIT license and Laravel Boost integration also lower risk and developer onboarding time."

For Engineering Leads: "This solves a recurring pain point: writing custom relationship methods for audit trails, array columns, or legacy migrations. With belongsToManyKeys, we can replace 5+ lines of manual query logic with a single method call, while hasManyArrayColumn eliminates the need for pivot tables in simple many-to-many cases. It’s battle-tested (174 stars, Laravel 11–13 support) and integrates with Boost for real-time IDE help—ideal for teams balancing speed and scalability."

For Developers: "No more writing boilerplate for audit logs or array relationships. Use belongsToManyKeys to map created_by, updated_by in one query, or hasManyArrayColumn to fetch related models from a JSON array. It’s like Eloquent’s hasMany but smarter—supports lazy loading, inverse relationships, and even string IDs. Plus, Boost gives you hints as you code!"

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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle