Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 847 Bytes

README.md

File metadata and controls

47 lines (37 loc) · 847 Bytes

LaravelEventStore

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