Download the PHP package liutao-me/laravel-transactional-model-events without Composer
On this page you can find all versions of the php package liutao-me/laravel-transactional-model-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download liutao-me/laravel-transactional-model-events
More information about liutao-me/laravel-transactional-model-events
Files in liutao-me/laravel-transactional-model-events
Package laravel-transactional-model-events
Short Description Add eloquent model events fired after a transaction is committed or rolled back
License MIT
Homepage https://github.com/liutao-me/laravel-transactional-model-events
Informations about the package laravel-transactional-model-events
Laravel Transactional Model Events
Add transactional events to your eloquent models. Will automatically detect changes in your models within a transaction and will fire events on commit or rollback. Should mimic the same functionality as transactional callbacks in Ruby on Rails.
You want to use this if you want to listen on events fired by models within a transaction and you want to be sure the transaction has completed successfully (or is rolled back).
Installation
You can install the package via composer:
Usage
Just add the trait TransactionalAwareEvents to your model or base model.
The following events will become available:
afterCommit.created
afterCommit.saved
afterCommit.updated
afterCommit.deleted
afterCommit.restored
afterCommit.forceDeleted
afterRollback.created
afterRollback.saved
afterRollback.updated
afterRollback.deleted
afterRollback.restored
afterRollback.forceDeleted
You can add listeners in you EventServiceProvider the same way as normal events
Or you can put them in your model boot method:
You should also be able to map them to event classes
And as icing on the cake, you can observe them with the following methods:
afterCommitCreated
afterCommitSaved
afterCommitUpdated
afterCommitDeleted
afterCommitRestored
afterCommitForceDeleted
afterRollbackCreated
afterRollbackSaved
afterRollbackUpdated
afterRollbackDeleted
afterRollbackRestored
afterRollbackForceDeleted
For example:
And register the observer in you ServiceProvider:
Multiple database connections are supported, events are triggered when the transaction is committed on the configured connection of the model.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Mark van Duijker
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-transactional-model-events with dependencies
illuminate/database Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0,!=6.9.0|~7.0|~8.0