PHP Classes

Fireworks Laravel Event Sourcing: Handle model class events in the object itself

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 26 All time: 11,196 This week: 455Up
Version License PHP version Categories
fireworks 1.0Custom (specified...7.1PHP 5, Databases, Libraries, Design P...
Description 

Author

This package can be used to handle model class events in the object itself.

It provides a trait that can be used in Laravel model classes to register callback functions of the model class itself to handle different types of events for changing the model object state.

The trait can call functions that model implementation classes and may have to execute actions before and after the creation, retrieving, updating and deleting model objects.

Innovation Award
PHP Programming Innovation award nominee
September 2020
Number 6
Laravel is a popular framework that makes it easy to create Web applications in PHP.

Among other benefits, it provides means to easily create model classes that can be used to store and retrieve application model object data in databases. These model classes implement functions to create, read, update and delete objects from the database.

This package provides a trait that can be used to register callback functions that can be used to integrate better the actions performed by model classes using external classes.

This way the organization of application functions can be improved by separating the actions of model classes from any custom actions that may need to be performed by other components.

Manuel Lemos
Picture of Hashemi Rafsan
  Performance   Level  
Name: Hashemi Rafsan <contact>
Classes: 7 packages by
Country: Bangladesh Bangladesh
Age: 28
All time rank: 382746 in Bangladesh Bangladesh
Week rank: 195 Up3 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 1x

Documentation

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.

Installation

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

composer require hashemi/fireworks

Setup

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 = [
        'name',
    ];
    // ....
    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";
        $model->save();
    }
    
    protected function onModelNameSaved($model, $newValue, $oldValue)
    {
        
    }
}

onModelCreating($model)

You can use `onModelCreatinginstead ofstatic::creating`

onModelUpdating($model)

You can use `onModelUpdatinginstead ofstatic::updating`

onModelSaving($model)

You can use `onModelSavinginstead ofstatic::saving`

onModelDeleting($model)

You can use `onModelDeletinginstead ofstatic::creating`

onModelRetrieved($model)

You can use `onModelRetrievedinstead ofstatic::creating`

onModelCreated($model)

You can use `onModelCreatedinstead ofstatic::created`

onModelUpdated($model)

You can use `onModelUpdatedinstead ofstatic::updated`

onModelSaved($model)

You can use `onModelSavedinstead ofstatic::saved`

onModelDeleted($model)

You can use `onModelDeletedinstead ofstatic::deleted`

Convention

  • 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()`.

Warning

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

Contributing

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


  Files folder image Files (5)  
File Role Description
Files folder imageexamples (1 file)
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  examples  
File Role Description
  Plain text file User.php Class Class source

  Files folder image Files (5)  /  src  
File Role Description
  Plain text file Fireworks.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:0
All time:11,196
This week:455Up