reallyli/laravel-event-store

Laravel event store

1.0.0 2019-11-08 03:56 UTC

This package is auto-updated.

Last update: 2022-05-08 10:46:58 UTC


README

1. Setup dependency

composer require tlikai/laravel-event-store

2. Setup database

php artisan migrate

3. Implementation ShouldBeStored interface

use App\User;
use Uniqueway\LaravelEventStore\ShouldBeStored;

class UserCreated implements ShouldBeStored
{
    public $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    // return stored event data
    public function getData()
    {
        return [
            'user_id' => $this->user->id,
        ];
    }
}

4. Fire events

$user = User::create(['name' => 'likai'])
event(new UserCreated($user));

Inspired by