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 Pivot Events Laravel Package

mikebronner/laravel-pivot-events

Adds Eloquent model events for many-to-many pivot operations: sync, attach, detach, and updateExistingPivot on BelongsToMany/MorphToMany. Listen for pivotSyncing/Synced, pivotAttaching/Attached, pivotDetaching/Detached, and pivotUpdating/Updated.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Real-Time Data Sync: Enables automatic reactions to pivot table changes (e.g., syncing user roles with permissions, updating inventory when product tags change) without manual polling or refreshes.
  • Audit & Compliance: Simplifies tracking changes to many-to-many relationships (e.g., logging role assignments, tracking tag edits) for regulatory or debugging purposes.
  • Decoupled Business Logic: Allows triggering side effects (e.g., notifications, analytics, or workflows) after pivot operations, reducing tight coupling in model methods.
  • Roadmap for Observability: Justifies adoption if future features require granular event-based triggers (e.g., soft-deletes, conditional pivot updates, or real-time UI updates).
  • Build vs. Buy: Eliminates the need to build custom pivot event listeners, saving development time and reducing technical debt.
  • Performance Optimization: Supports efficient event handling (e.g., batching changes in sync()) to minimize overhead in high-traffic systems.

When to Consider This Package

Adopt if:

  • Your application relies on many-to-many or morph-to-many relationships (e.g., tags, roles, user-groups) where real-time reactions to pivot changes are critical.
  • You need to audit, log, or trigger actions based on pivot table modifications (e.g., "notify admin when a user’s role changes").
  • You’re using Laravel 11+ and want to avoid reinventing pivot event handling.
  • Your team prefers event-driven architecture over manual checks (e.g., polling pivot tables or using syncWithoutEvents).
  • You require compatibility with Laravel Telescope or Model Caching (this package was forked to address those integrations).

Look elsewhere if:

  • Your pivot logic is simple (e.g., no side effects needed) and doesn’t require event-based reactions.
  • You’re not using Laravel/Eloquent (e.g., Symfony, Django, or raw SQL).
  • You need complex pivot validation (e.g., custom rules before/after pivot updates)—consider Laravel’s built-in syncWithoutEvents or custom observers.
  • Your application has extremely high-frequency pivot updates where event overhead could impact performance (benchmark first).
  • You’re using older Laravel versions (pre-11.0) or PHP < 8.2.

How to Pitch It (Stakeholders)

For Executives: "This package lets us automatically respond to changes in relationships between data—like when a user’s role is updated or a product gets a new tag—without manual code. For example, if a customer’s subscription tier changes, we can instantly update their dashboard or log the change for compliance. It’s a low-risk, high-reward solution that saves development time and reduces errors from missed updates. Think of it as ‘autopilot’ for your many-to-many data connections."

For Engineering: *"Laravel Pivot Events (v13.1.0) is a lightweight package that adds pivot-specific Eloquent events (e.g., pivotSynced, pivotAttached) to trigger actions when many-to-many relationships change. Key benefits:

  • No more manual tracking: Events fire automatically for sync(), attach(), detach(), and updateExistingPivot().
  • Optimized for performance: Recent updates (e.g., suppressing redundant pivotSynced events) reduce noise in your listeners.
  • Seamless integration: Works with Laravel’s native event system, queues, and observers.
  • Future-proof: Supports Laravel 11+ and PHP 8.2+, with active maintenance.

Use this for:

  • Real-time UI updates (e.g., role-based access changes).
  • Audit logging or compliance tracking.
  • Decoupled workflows (e.g., sending notifications when pivots change).

Example: If a user’s roles() relationship updates, you can log the change, trigger a notification, or update cached permissions—all without modifying your core business logic. Recommended for apps with dynamic relationships needing real-time reactions."*

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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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
christhompsontldr/laravel-inky
spatie/mailcoach-vapor