neylsongularte/eloquent-extra-events

There is no license information available for the latest version (1.0.0) of this package.

Eventos adicionais para o eloquent

1.0.0 2017-10-13 23:47 UTC

This package is not auto-updated.

Last update: 2024-05-19 07:05:47 UTC


README

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

Install:

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

In your model:

use NeylsonGularte\EloquentExtraEvents\ExtraEventsTrait;

Events:

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

Listen events in 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) {
});

Available properties:

  • $eventData['parent_model']: string e.g. 'App\Models\Model'
  • $eventData['parent_id']: integer e.g. 42
  • $eventData['related_model']: string e.g. 'App\Models\Model'
  • (except eloquent.synced) $eventData['related_ids']: array e.g. [31,41]
  • (Only eloquent.detached) $eventData['results']: integer e.g. 2
  • (Only eloquent.synced) $eventData['changes']: array with the following keys:
    • 'attached': array e.g. [1, 8]
    • 'detached': array e.g. [15, 16]
    • 'updated': array e.g. [23]

Note: sync trigger attach and detach.