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

chelout/laravel-relationship-events

Adds missing Eloquent relationship events to Laravel models. Use simple traits (HasOne/Many, BelongsTo/Many, Morph*) to listen for attach/detach/sync, saved/updated, and other relation lifecycle hooks with parent/related context and IDs/attributes.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Event-Driven Architecture: Enables real-time reactions to relationship changes (e.g., triggering notifications, audits, or workflows when a user updates their profile).
  • Decoupled Logic: Shifts relationship-dependent logic (e.g., syncing external services, caching, or analytics) from business logic to event listeners, improving modularity.
  • Observability: Adds granular tracking of relationship operations (e.g., debugging, monitoring, or compliance logging) without modifying core models.
  • Build vs. Buy: Avoids reinventing relationship event handling, reducing dev time for custom solutions (e.g., observers or model hooks).
  • Roadmap Priorities:
    • Phase 1: Integrate for critical workflows (e.g., user-profile updates, order-item changes).
    • Phase 2: Expand to polymorphic relationships (e.g., tagging systems, multi-model associations).
    • Phase 3: Replace legacy observers or custom event systems with standardized hooks.

When to Consider This Package

  • Adopt When:

    • Your app relies on reactive logic tied to Eloquent relationships (e.g., "When a user updates their address, notify their admin").
    • You need fine-grained control over relationship lifecycle events (e.g., pre/post-save validation, side effects).
    • Your team uses Laravel 10+ and PHP 8.1+ (or compatible versions).
    • You want to replace ad-hoc observers or complex model hooks with a standardized, maintainable approach.
    • Your use cases include polymorphic relationships (e.g., tags, comments, or dynamic associations).
  • Look Elsewhere If:

    • You’re using non-Laravel PHP or a framework without Eloquent.
    • Your needs are simple (e.g., basic CRUD without relationship events).
    • You require real-time sync (consider Laravel Echo/Pusher for WebSocket events).
    • Your team prefers database triggers or application-level services over Eloquent hooks.
    • You need transactional outbox patterns (combine with spatie/laravel-queueable-events).

How to Pitch It (Stakeholders)

For Executives: "This package lets us react instantly to changes in our data relationships—like sending alerts when a user updates their profile or syncing inventory when an order item is modified—without bloating our models. It’s like adding ‘triggers’ for Eloquent relationships, but cleaner and more scalable than custom code. We can use it to automate workflows, improve auditing, and reduce bugs in critical paths."

For Engineers: *"This solves the ‘spaghetti event’ problem in Laravel. Instead of scattering logic across observers, model hooks, or service layers, we can centralize relationship events (e.g., hasOneSaved, morphToManyAttached) in listeners. It’s well-documented, supports all Laravel relationship types, and integrates with dispatchable events. For example, we can:

  • Audit changes: Log every time a belongsTo association is updated.
  • Sync external APIs: Trigger a webhook when a hasMany record is created.
  • Debug issues: Add breakpoints to polymorphic relationship events. It’s a drop-in replacement for manual event handling and plays nicely with Laravel’s ecosystem."*

Key Selling Points:

  • Reduces Technical Debt: Standardizes event handling across the codebase.
  • Enables New Features: Unlocks real-time features with minimal effort (e.g., "What if we notified users when their tags changed?").
  • Low Risk: MIT-licensed, actively maintained, and battle-tested in Laravel apps.
  • Future-Proof: Works with Laravel’s latest versions and supports polymorphic relationships.
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