Skip to content
An elegant way to trigger Laravel events based on attributes changes.
PHP
Branch: master
Clone or download
Boris Lepikhin
Boris Lepikhin Update travis.yml
Latest commit d234e6e Oct 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Refactoring Oct 3, 2019
tests Update version constraints Oct 1, 2019
.gitattributes Add .gitattributes Oct 2, 2019
.gitignore Update .gitignore Oct 2, 2019
.styleci.yml Initial commit Sep 18, 2019
.travis.yml Update travis.yml Oct 7, 2019
changelog.md Initial commit Sep 18, 2019
composer.json Upgrade min version of PHP to 7.2 Oct 7, 2019
contributing.md Initial commit Sep 18, 2019
license.md Initial commit Sep 18, 2019
phpunit.xml.dist Update phpunit.xml Oct 2, 2019
readme.md Update readme.md Sep 20, 2019

readme.md

Fireable

Latest Version on Packagist StyleCI Build Status Total Downloads

An elegant way to trigger events based on attributes changes.

Installation

Install package through Composer

$ composer require envant/fireable

Usage

  1. Add the FireableAttributes trait to your model
  2. Define the attributes with specified events via the protected $fireableAttributes property on the model

Example

Let's say we need to trigger specified events when specific model attributes are updated.

For example, you need to notify user when he gets an "approved" status. Instead of observing model's "dirty" attributes and firing events manually we could do it more elegantly by assigning specified events to attributes or even certain values of attributes.

class User extends Authenticatable
{
    use FireableAttributes;

    protected $fireableAttributes = [
        'status' => [
            'approved' => UserApproved::class,
            'rejected' => UserRejected::class,
        ],
    ];
}

Also you may not need to track certain values, so you can assign an event directly to an attribute itself. So, in the example below, each time the user's email is changed, the appropriate event will be fired.

class User extends Authenticatable
{
    use FireableAttributes;

    protected $fireableAttributes = [
        'email' => EmailUpdated::class,
    ];
}

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

You can’t perform that action at this time.