PHPackages                             signifly/laravel-pivot-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. [Database &amp; ORM](/categories/database)
4. /
5. signifly/laravel-pivot-events

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

signifly/laravel-pivot-events
=============================

Trigger Eloquent model pivot events when attaching, detaching or updating.

v2.0.1(2y ago)1055.7k—0%5[2 PRs](https://github.com/signifly/laravel-pivot-events/pulls)MITPHPPHP ^7.4|^8.0

Since Apr 24Pushed 2y ago4 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

Easily add Eloquent model pivot events to your Laravel app
==========================================================

[](#easily-add-eloquent-model-pivot-events-to-your-laravel-app)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b35c977507cc0cda46de4a21bbd6bad1532cf829fc21bfff62904e1eb44a9d50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7369676e69666c792f6c61726176656c2d7069766f742d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/signifly/laravel-pivot-events)[![Build Status](https://camo.githubusercontent.com/d36eeebbdd51524c99065cc0a3bb5d88db77e2afa2b0ab9ae31b2b175597b95f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7369676e69666c792f6c61726176656c2d7069766f742d6576656e74732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/signifly/laravel-pivot-events)[![StyleCI](https://camo.githubusercontent.com/ae09aa01742f25faa3ad71f6ff7efcb0aed28ea4b7dbc47ecc4326987ab9ebe3/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133303835323336352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/130852365)[![Quality Score](https://camo.githubusercontent.com/86cc1f6dfd1e8ba221e65991315df095708e54bdbeda8ad9aaf9b3630a02b65a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7369676e69666c792f6c61726176656c2d7069766f742d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/signifly/laravel-pivot-events)[![Total Downloads](https://camo.githubusercontent.com/eba76a293d6445651b3ac70de4b2e71c58fe7db05b6faf8fdb91c8dc3e13654a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7369676e69666c792f6c61726176656c2d7069766f742d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/signifly/laravel-pivot-events)

The `signifly/laravel-pivot-events` package allows you to easily add Eloquent model pivots events to your Laravel app.

Below is a small example of how to use it.

```
// Remember to add use statement
use Signifly\PivotEvents\HasPivotEvents;

class User
{
    use HasPivotEvents;
}
```

Now you would be able to listen for the newly available pivot events:

```
use Signifly\PivotEvents\HasPivotEvents;

class User
{
    use HasPivotEvents;

    protected static function boot()
    {
        static::pivotAttaching(function ($model) {
            // To get related changes
            $model->getPivotChanges();
            // return Collection(['attach' => ['roles' => [1 => ['scopes' => 'orders']]]])

            // To get related changes for a specific type
            $model->getPivotChanges('attach');
            // return Collection(['roles' => [1 => ['scopes' => 'orders']]])

            // You can get nested changes
            // values are $id => $attributes
            $model->getPivotChanges('attach.roles');
            // return Collection([1 => ['scopes' => 'orders']])

            // To get related ids for a specific type and relation
            $model->getPivotChangeIds('attach', 'roles');
            // return Collection([1])
        });

        static::pivotAttached(function ($model) {
            //
        });

        static::pivotDetaching(function ($model) {
            //
        });

        static::pivotDetached(function ($model) {
            //
        });

        static::pivotUpdating(function ($model) {
            //
        });

        static::pivotUpdated(function ($model) {
            //
        });
    }
}
```

You can also use observers for the available events: `pivotAttaching`, `pivotAttached`, `pivotDetaching`, `pivotDetached`, `pivotUpdating`, `pivotUpdated`.

Documentation
-------------

[](#documentation)

Until further documentation is provided, please have a look at the tests.

Installation
------------

[](#installation)

You can install the package via composer:

```
$ composer require signifly/laravel-pivot-events
```

The package will automatically register itself.

Testing
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Morten Poul Jensen](https://github.com/pactode)
- [Travis Elkins](https://github.com/telkins)
- [All contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 92.5% 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

Every ~145 days

Recently: every ~339 days

Total

15

Last Release

903d ago

Major Versions

v1.5.2 → v2.0.02023-11-21

PHP version history (4 changes)v1.0.0PHP ^7.1

v1.5.0PHP ^7.2.5

v1.5.2PHP ^7.2.5|^8

v2.0.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd06d3bd4452ca3ce5c956b4c0bcb1240ca692f590bc4cdabe104fd07156e0bf?d=identicon)[signifly](/maintainers/signifly)

---

Top Contributors

[![pactode](https://avatars.githubusercontent.com/u/5956778?v=4)](https://github.com/pactode "pactode (37 commits)")[![Razorsheep](https://avatars.githubusercontent.com/u/459217?v=4)](https://github.com/Razorsheep "Razorsheep (2 commits)")[![matthewnessworthy](https://avatars.githubusercontent.com/u/5653887?v=4)](https://github.com/matthewnessworthy "matthewnessworthy (1 commits)")

---

Tags

eloquentlaravelpivot-tables

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/signifly-laravel-pivot-events/health.svg)

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

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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