genesis-tecnologia/laravel-eloquent-extra-events

此包的最新版本(dev-master)没有可用的许可信息。

为Eloquent添加额外事件

dev-master 2023-02-10 15:25 UTC

This package is not auto-updated.

Last update: 2024-09-21 21:32:04 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 genesistecnologia/eloquent-extra-events:0.3.5
For 5.5.x:
composer require genesistecnologia/eloquent-extra-events

在你的模型中

use GenesisTecnologia\LaravelEloquentExtraEvents\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'
  • (except eloquent.synced) $eventData['related_ids']: array 例如 [31,41]
  • (Only eloquent.detached) $eventData['results']: integer 例如 2
  • (Only eloquent.synced) $eventData['changes']: array 包含以下键
    • 'attached': array 例如 [1, 8]
    • 'detached': array 例如 [15, 16]
    • 'updated': array 例如 [23]

注意:sync触发attach和detach。