Skip to content
EventSauce bindings for Laravel apps
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
database/migrations
src
tests Add some initial docs Sep 30, 2019
.gitattributes cleanup May 13, 2019
.gitignore
.styleci.yml
.travis.yml
CHANGELOG.md Update CHANGELOG.md Aug 29, 2019
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

Laravel EventSauce

Packagist Version Travis Downloads

This library is a work in progress. More docs coming soon...

Table of Contents

Requirements

  • PHP ^7.3
  • Laravel ^6.0

Installation

You can install the library through Composer. This will also install the main EventSauce library.

composer require eventsauce/laravel-eventsauce

Configuration

You can publish the config file with the following command:

php artisan vendor:publish --tag="eventsauce-config"

Migrations

The default domain_messages table will be loaded in through the library's service provider and migrated with:

php artisan migrate

You can also publish it and modify it as you see fit with the following command:

php artisan vendor:publish --tag="eventsauce-migrations"

Default Connection

The default database connection can be modified by setting the EVENTSAUCE_CONNECTION env variable:

EVENTSAUCE_CONNECTION=mysql

Default Table

The default table name for your domain messages can be set with the EVENTSAUCE_TABLE env variable:

EVENTSAUCE_TABLE=event_store

Generating Commands & Events

EventSauce can generate commands and events for you so you don't need to write these yourself. First, define a commands_and_events.yml file which contains your definitions:

namespace: App\Domain\Registration
commands:
  ConfirmUser:
    fields:
      identifier: RegistrationAggregateRootId
      user_id: int
events:
  UserWasConfirmed:
    fields:
      identifier: RegistrationAggregateRootId
      user_id: int

Then define the input and output output file in the AggregateRootRepository:

final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
    ...

    /** @var string */
    protected static $inputFile = __DIR__.'/commands_and_events.yml';

    /** @var string */
    protected static $outputFile = __DIR__.'/commands_and_events.php';
}

And register the AggregateRootRepository in your eventsauce.php config file:

'repositories' => [
    App\Domain\Registration\RegistrationAggregateRootRepository::class,
],

You can now generate commands and events for all repositories that you've added by running the following command:

php artisan eventsauce:generate

For more info on creating events and commands with EventSauce, as well as how to define different types, see: https://eventsauce.io/docs/getting-started/create-events-and-commands

Acknowledgments

Thanks to Frank De Jonge for building EventSauce. Thanks to Freek Van der Herten and Spatie's Laravel EventSauce library for inspiration to some of the features in this package.

License

The MIT License. Please see the License File for more information.

You can’t perform that action at this time.