PHPackages                             sameedkun/laravel-relationship-events - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sameedkun/laravel-relationship-events

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sameedkun/laravel-relationship-events
=====================================

Missing relationship events for Laravel — actively maintained fork of chelout/laravel-relationship-events

v1.0.0(3w ago)023↓53.3%MITPHPPHP ^8.3

Since May 19Pushed 3w agoCompare

[ Source](https://github.com/sameedkun/laravel-relationship-events)[ Packagist](https://packagist.org/packages/sameedkun/laravel-relationship-events)[ Docs](https://github.com/sameedkun/laravel-relationship-events)[ RSS](/packages/sameedkun-laravel-relationship-events/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Laravel Relationship Events
===========================

[](#laravel-relationship-events)

Missing relationship events for Laravel — actively maintained fork of [chelout/laravel-relationship-events](https://github.com/chelout/laravel-relationship-events)

> **Note:** The original package by [@chelout](https://github.com/chelout) has been inactive since 2020. This fork picks up where it left off, with Laravel 13 support and active maintenance.

 [![Build Status](https://github.com/sameedkun/laravel-relationship-events/workflows/tests/badge.svg)](https://github.com/sameedkun/laravel-relationship-events/actions) [![Total Downloads](https://camo.githubusercontent.com/37c043fca2d64fee20ce4cb91cee2c141966cae2590e71daf5470308ec608cf3/68747470733a2f2f706f7365722e707567782e6f72672f73616d6565646b756e2f6c61726176656c2d72656c6174696f6e736869702d6576656e74732f642f746f74616c2e737667)](https://packagist.org/packages/sameedkun/laravel-relationship-events) [![Latest Stable Version](https://camo.githubusercontent.com/3993cae9d9fe73f67d9f9eaa71477be7523bf85fc3faf0e21170070ef9b122c5/68747470733a2f2f706f7365722e707567782e6f72672f73616d6565646b756e2f6c61726176656c2d72656c6174696f6e736869702d6576656e74732f762f737461626c652e737667)](https://packagist.org/packages/sameedkun/laravel-relationship-events) [![License](https://camo.githubusercontent.com/ed5c013db14a3d497f156167ade3440c8726f1ed6cb0c725fcee183bac3cef84/68747470733a2f2f706f7365722e707567782e6f72672f73616d6565646b756e2f6c61726176656c2d72656c6174696f6e736869702d6576656e74732f6c6963656e73652e737667)](https://packagist.org/packages/sameedkun/laravel-relationship-events)

Compatibility
-------------

[](#compatibility)

PackageLaravelPHP`v5.x``12.x`, `13.x``^8.3``v4.x``11.x`, `12.x``^8.2`Migrating from `chelout/laravel-relationship-events`
----------------------------------------------------

[](#migrating-from-cheloutlaravel-relationship-events)

Already using the original package? Switching is seamless — no code changes required. The namespace, traits, and events are all identical.

Just swap the package name in your `composer.json`:

```
composer remove chelout/laravel-relationship-events
composer require sameedkun/laravel-relationship-events
```

Install
-------

[](#install)

1. Install package with composer

```
composer require sameedkun/laravel-relationship-events
```

2. Use necessary trait in your model.

#### Available traits:

[](#available-traits)

- HasOneEvents
- HasBelongsToEvents
- HasManyEvents
- HasBelongsToManyEvents
- HasMorphOneEvents
- HasMorphToEvents
- HasMorphManyEvents
- HasMorphToManyEvents
- HasMorphedByManyEvents

```
use Chelout\RelationshipEvents\Concerns\HasOneEvents;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasOneEvents;

    public static function boot()
    {
        parent::boot();

        static::hasOneSaved(function ($parent, $related) {
            dump('hasOneSaved', $parent, $related);
        });

        static::hasOneUpdated(function ($parent, $related) {
            dump('hasOneUpdated', $parent, $related);
        });
    }
}
```

```
use Chelout\RelationshipEvents\Concerns\HasMorphToManyEvents;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasMorphToManyEvents;

    public static function boot()
    {
        parent::boot();

        static::morphToManyAttached(function ($relation, $parent, $ids, $attributes) {
            dump('morphToManyAttached', $relation, $parent, $ids, $attributes);
        });

        static::morphToManyDetached(function ($relation, $parent, $ids) {
            dump('morphToManyDetached', $relation, $parent, $ids);
        });
    }

    public function tags()
    {
        return $this->morphToMany(Tag::class, 'taggable');
    }
}
```

3. Dispatchable relationship events.

It is possible to fire event classes via `$dispatchesEvents` property and adding `HasDispatchableEvents` trait:

```
use Chelout\RelationshipEvents\Concerns\HasOneEvents;
use Chelout\RelationshipEvents\Traits\HasDispatchableEvents;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasDispatchableEvents;
    use HasOneEvents;

    protected $dispatchesEvents = [
        'hasOneSaved' => HasOneSaved::class,
    ];
}
```

Relationships
-------------

[](#relationships)

- [One To One Relations](doc/1-one-to-one.md)
- [One To Many Relations](doc/2-one-to-many.md)
- [Many To Many Relations](doc/3-many-to-many.md)
- [Has Many Through Relations](doc/4-has-many-through.md)
- [One To One Polymorphic Relations](doc/5-one-to-one-polymorphic.md)
- [One To Many Polymorphic Relations](doc/6-one-to-many-polymorphic.md)
- [Many To Many Polymorphic Relations](doc/7-many-to-many-polymorphic.md)

Observers
---------

[](#observers)

Starting from v0.4 it is possible to use relationship events in [Laravel observer classes](https://laravel.com/docs/eloquent#observers). Add `HasRelationshipObservables` trait to your model and define an observer:

```
namespace App\Observer;

class UserObserver
{
    public function hasOneCreating(User $user, Model $related)
    {
        Log::info("Creating profile for user {$related->name}.");
    }

    public function hasOneCreated(User $user, Model $related)
    {
        Log::info("Profile for user {$related->name} has been created.");
    }
}
```

Register the observer in `AppServiceProvider`:

```
public function boot()
{
    User::observe(UserObserver::class);
}
```

Credits
-------

[](#credits)

- Original package by [@chelout](https://github.com/chelout) — [chelout/laravel-relationship-events](https://github.com/chelout/laravel-relationship-events)
- Maintained by [@sameedkun](https://github.com/sameedkun)

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65105add059b8e7e69989de4f1249b55b7c2edcd3a6285252955b3b7d2172fca?d=identicon)[Mahiru](/maintainers/Mahiru)

---

Top Contributors

[![chelout](https://avatars.githubusercontent.com/u/9196257?v=4)](https://github.com/chelout "chelout (158 commits)")[![saleem-hadad](https://avatars.githubusercontent.com/u/12780866?v=4)](https://github.com/saleem-hadad "saleem-hadad (19 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (5 commits)")[![sameedkun](https://avatars.githubusercontent.com/u/118528600?v=4)](https://github.com/sameedkun "sameedkun (3 commits)")[![nhedger](https://avatars.githubusercontent.com/u/649677?v=4)](https://github.com/nhedger "nhedger (2 commits)")[![waltoncon](https://avatars.githubusercontent.com/u/7566870?v=4)](https://github.com/waltoncon "waltoncon (1 commits)")[![giekus](https://avatars.githubusercontent.com/u/52037203?v=4)](https://github.com/giekus "giekus (1 commits)")[![alvin-nt](https://avatars.githubusercontent.com/u/5227472?v=4)](https://github.com/alvin-nt "alvin-nt (1 commits)")

---

Tags

laraveleventsrelationsrelationship

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sameedkun-laravel-relationship-events/health.svg)

```
[![Health](https://phpackages.com/badges/sameedkun-laravel-relationship-events/health.svg)](https://phpackages.com/packages/sameedkun-laravel-relationship-events)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5232.4M17](/packages/chelout-laravel-relationship-events)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.4k](/packages/larastan-larastan)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M84](/packages/mongodb-laravel-mongodb)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
