neylsongularte/eloquent-extra-events

此包最新版本(1.0.0)没有提供许可证信息。

eloquent 的额外事件

1.0.0 2017-10-13 23:47 UTC

This package is not auto-updated.

Last update: 2024-09-22 08:42:47 UTC


README

Total Downloads Monthly Downloads Daily Downloads Latest Stable Version Latest Unstable Version License

安装

For 5.2.x, 5.3.x and 5.4.x:
composer require neylsongularte/eloquent-extra-events:0.3.5
For 5.5.x:
composer require neylsongularte/eloquent-extra-events

在你的模型中

use NeylsonGularte\EloquentExtraEvents\ExtraEventsTrait;

事件

  • eloquent.syncing
  • eloquent.synced
  • eloquent.attaching
  • eloquent.attached
  • eloquent.detaching
  • eloquent.detached

App\Providers\AppServiceProvider 中监听事件

In 5.2.x and 5.3.x:
Event::listen('eloquent.syncing*', function (array $eventData) {
});

In 5.4.x and 5.5.x:
Event::listen('eloquent.syncing*', function ($eventName, array $eventData) {
});

可用属性

  • $eventData['parent_model']: string 例如 'App\Models\Model'
  • $eventData['parent_id']: integer 例如 42
  • $eventData['related_model']: string 例如 'App\Models\Model'
  • (除了 eloquent.synced) $eventData['related_ids']: array 例如 [31,41]
  • (仅 eloquent.detached) $eventData['results']: integer 例如 2
  • (仅 eloquent.synced) $eventData['changes']: array 包含以下键
    • 'attached': array 例如 [1, 8]
    • 'detached': array 例如 [15, 16]
    • 'updated': array 例如 [23]

注意:sync 触发 attach 和 detach。