2017 © Pedro Peláez
 

library laravel-pivot-events

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

image

signifly/laravel-pivot-events

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

  • Wednesday, May 16, 2018
  • by signifly
  • Repository
  • 3 Watchers
  • 2 Stars
  • 346 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 88 % Grown

The README.md

Easily add Eloquent model pivot events to your Laravel app

Latest Version on Packagist Build Status StyleCI Quality Score Total Downloads, (*1)

The signifly/laravel-pivot-events package allows you to easily add Eloquent model pivots events to your Laravel app., (*2)

Below is a small example of how to use it., (*3)

// 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:, (*4)

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., (*5)

Documentation

Until further documentation is provided, please have a look at the tests., (*6)

Installation

You can install the package via composer:, (*7)

$ composer require signifly/laravel-pivot-events

The package will automatically register itself., (*8)

Testing

$ composer test

Security

If you discover any security issues, please email dev@signifly.com instead of using the issue tracker., (*9)

Credits

License

The MIT License (MIT). Please see License File for more information., (*10)

The Versions

16/05 2018

dev-master

9999999-dev https://github.com/signifly/laravel-pivot-events

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis Elkins
by Morten Poul Jensen

16/05 2018

v1.1.1

1.1.1.0 https://github.com/signifly/laravel-pivot-events

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis Elkins
by Morten Poul Jensen

25/04 2018

v1.1.0

1.1.0.0 https://github.com/signifly/laravel-pivot-events

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis Elkins
by Morten Poul Jensen

24/04 2018

v1.0.1

1.0.1.0 https://github.com/signifly/laravel-pivot-events

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis Elkins
by Morten Poul Jensen

24/04 2018

v1.0.0

1.0.0.0 https://github.com/signifly/laravel-pivot-events

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis Elkins
by Morten Poul Jensen