PHP Classes


Recommend this page to a friend!
  Classes of Hashemi Rafsan  >  Fireworks Laravel Event Sourcing  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Fireworks Laravel Event Sourcing
Handle model class events in the object itself
Author: By
Last change:
Date: 2 years ago
Size: 3,381 bytes


Class file image Download

Laravel Fireworks

A simple trait that will help to fire model property wise event on your laravel model. Using laravel model events, to create hooks with changed column and data.


You can start it from composer. Go to your terminal and run this command from your project root directory.

composer require hashemi/fireworks


At first, you need to use Fireworks trait on your model where you want register your model events.

class User extends Model
    // Use Fireworks Trait
    // ....
    use \Hashemi\Fireworks\Fireworks;
    // ....

`Fireworkstrait addbootmethod on your model and register pre-defined model event hooks that already provided by laravel. This package supportsretrieved, creating, created, updating, updated, deleting, deleted, saving, savedhooks. So, you don't need to register again this hooks are onboot` method.

How to use

This package will help you figure out of every hooks in methods. Example: suppose you want to use `creatinghooks, just declareonModelCreating` method on your model.

class User extends Model
    // Use Fireworks Trait
    // ....
    use \Hashemi\Fireworks\Fireworks;
    protected $fillable = [
    // ....
    protected function onModelCreating($model) {
        $model->name = "Kuddus";

    protected function onModelUpdating($model) {}

    protected function onModelSaving($model) {}
    protected function onModelCreated($model) {}

    protected function onModelUpdated($model) {}

    protected function onModelSaved($model) {
        $model->name = "Ali";
    protected function onModelNameSaved($model, $newValue, $oldValue)


You can use `onModelCreatinginstead ofstatic::creating`


You can use `onModelUpdatinginstead ofstatic::updating`


You can use `onModelSavinginstead ofstatic::saving`


You can use `onModelDeletinginstead ofstatic::creating`


You can use `onModelRetrievedinstead ofstatic::creating`


You can use `onModelCreatedinstead ofstatic::created`


You can use `onModelUpdatedinstead ofstatic::updated`


You can use `onModelSavedinstead ofstatic::saved`


You can use `onModelDeletedinstead ofstatic::deleted`


  • Your hooks method should be `onModelformat. Where the` will be replaced by the StudlyCase Hooks names. So, if your hook is `creating`, then the method name should be `onModelCreating()`.
  • If you want to fire event on column change wise then your hook method should be `onModel<PropertyName><Hookname>`. Where the `PropertyName` will be replaced with your column name in StudlyCase and `Hookname` will be also same way. So if your column is `phone_number` and your hook is `updating`, then the method name should be `onModelPhoneNumberUpdating()`.


Please use hooks proper way other way data will modified in each hook.


Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.

For more information send a message to info at phpclasses dot org.