signifly/laravel-pivot-events 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

signifly/laravel-pivot-events

最新稳定版本:v2.0.1

Composer 安装命令:

composer require signifly/laravel-pivot-events

包简介

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

README 文档

README

Latest Version on Packagist Build Status StyleCI Quality Score Total Downloads

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

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

Installation

You can install the package via composer:

$ composer require signifly/laravel-pivot-events

The package will automatically register itself.

Testing

$ composer test

Security

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

Credits

License

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

统计信息

  • 总下载量: 55.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-24