slavcodev/laravel-event-recorder

Laravel Eloquent event recorder

0.1.0 2024-03-30 00:24 UTC

This package is auto-updated.

Last update: 2024-04-30 00:57:01 UTC


README

phpunit psalm php-cs-fixer Latest Version License License

Event recorder trait useful when an event should be emitted only after model successfully saved.

Installation

Using Composer

composer require slavcodev/laravel-event-recorder

Usage

Just add the trait to any of you Eloquent model, it adds recordEvent($event) method and registers listener to emit all recorded events after save.

class User extends \Illuminate\Database\Eloquent\Model
{
    use \Slavcodev\Laravel\Events\EventRecorder;
    
    public function someModifications()
    {
        $this->recordEvent(new UserChanged());
    }
}

Testing

phpunit

Contributing

Please see CONTRIBUTING and CODE OF CONDUCT for more details.