PHPackages                             eventsauce/laravel-eventsauce - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eventsauce/laravel-eventsauce

ActiveLibrary

eventsauce/laravel-eventsauce
=============================

Integration support for EventSauce with the Laravel framework.

0.6.0(4y ago)9860.8k18[5 issues](https://github.com/EventSaucePHP/LaravelEventSauce/issues)[6 PRs](https://github.com/EventSaucePHP/LaravelEventSauce/pulls)MITPHPPHP ^7.4|^8.0

Since Aug 29Pushed 1y ago4 watchersCompare

[ Source](https://github.com/EventSaucePHP/LaravelEventSauce)[ Packagist](https://packagist.org/packages/eventsauce/laravel-eventsauce)[ GitHub Sponsors](https://github.com/driesvints)[ RSS](/packages/eventsauce-laravel-eventsauce/feed)WikiDiscussions main Synced yesterday

READMEChangelog (8)Dependencies (8)Versions (10)Used By (0)

 [ ![](https://camo.githubusercontent.com/bb7103ec65390265f0c0cb66a8a182e699cc9929b6b02425b2b5894dae3dcc20/68747470733a2f2f6576656e7473617563652e696f2f7374617469632f6c6f676f2e737667) ](https://eventsauce.io)

 [ ![Build Status](https://github.com/EventSaucePHP/LaravelEventSauce/workflows/Tests/badge.svg) ](https://github.com/EventSaucePHP/LaravelEventSauce/actions?query=workflow%3ATests) [ ![Code Style](https://camo.githubusercontent.com/426c0740222b3fc41ddd25344630ffe53970fcb3f2f81cb6534a9b1e0ca49dde/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134363836393732322f736869656c643f7374796c653d666c6174) ](https://github.styleci.io/repos/146869722) [ ![Latest Stable Version](https://camo.githubusercontent.com/1231b3e9056c6922708c232f0aa0197cdd038b6b2da39b9d1979a3c099873e98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6576656e7473617563652f6c61726176656c2d6576656e7473617563652e737667) ](https://packagist.org/packages/eventsauce/laravel-eventsauce) [ ![Total Downloads](https://camo.githubusercontent.com/b34ee07f7559d6d0be317883dfc4302a65003b40abd2d9d4dc7c72a8d740d412/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6576656e7473617563652f6c61726176656c2d6576656e7473617563652e737667) ](https://packagist.org/packages/eventsauce/laravel-eventsauce)

Laravel EventSauce
==================

[](#laravel-eventsauce)

> 👋 [This project is currently looking for a new maintainer.](https://github.com/EventSaucePHP/LaravelEventSauce/issues/28)

This library allows you to easily integrate [EventSauce](https://eventsauce.io) with your Laravel application. It takes out the tedious work of having to set up your own message dispatcher and provides an easy API to set up [aggregate roots](#aggregate-roots), [aggregate root repositories](#aggregate-root-repositories), [consumers](#consumers), and more. It also comes with a range of scaffolding console commands to easily generate the boilerplate needed to get started with an Event Sourced application.

> ⚠️ While already usable, this library is currently still a work in progress. More documentation and features will be added over time. We appreciate pull requests that help extend and improve this project.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Laravel 8.0 or higher

Installation
------------

[](#installation)

Before installing a new package it's always a good idea to clear your config cache:

```
php artisan config:clear
```

You can install the library through [Composer](https://getcomposer.org). This will also install [the main EventSauce library](https://github.com/EventSaucePHP/EventSauce).

```
composer require eventsauce/laravel-eventsauce
```

Configuration
-------------

[](#configuration)

You can publish the config file with the following command:

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

### Migrations

[](#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

[](#default-connection)

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

```
EVENTSAUCE_CONNECTION=mysql
```

### Default Table

[](#default-table)

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

```
EVENTSAUCE_TABLE=event_store
```

Scaffolding
-----------

[](#scaffolding)

Laravel EventSauce comes with some commands that you can use to scaffold objects and files which you'll need to build your Event Sourced app. These commands take out the tedious work of writing these yourself and instead let you focus on actually writing your domain logic.

### Generating Aggregate Roots

[](#generating-aggregate-roots)

Laravel EventSauce can generate [aggregate roots](#aggregate-roots) and its related files for you. By using the `make:aggregate-root` command, you can generate the following objects and files:

- The `AggregateRoot`
- The `AggregateRootId`
- The `AggregateRootRepository`
- The migration file

To generate these files for a "Registration" process, run the following command:

```
php artisan make:aggregate-root Domain/Registration
```

This will scaffold the following files:

- `App\Domain\Registration`
- `App\Domain\RegistrationId`
- `App\Domain\RegistrationRepository`
- `database/migrations/xxxx_xx_xx_create_registration_domain_messages_table.php`

These are all the files you need to get started with an .

### Generating Consumers

[](#generating-consumers)

Laravel EventSauce can also generate [consumers](#consumers) for you. For example, run the `make:consumer` command to generate a `SendEmailConfirmation` process manager:

```
php artisan make:consumer Domain/SendEmailConfirmation
```

This will create a class at `App\Domain\SendEmailConfirmation` where you can now define `handle{EventName}` methods to handle events.

### Generating Commands &amp; Events

[](#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 the EventSauce documentation](https://eventsauce.io/docs/event-sourcing/create-events-and-commands).

Usage
-----

[](#usage)

### Aggregate Roots

[](#aggregate-roots)

More docs coming soon...

### Aggregate Root Repositories

[](#aggregate-root-repositories)

More docs coming soon...

#### Queue Property

[](#queue-property)

You can instruct Laravel to queue all consumers onto a specific queue by setting the `$queue` property:

```
use App\Domain\SendConfirmationNotification;
use EventSauce\LaravelEventSauce\AggregateRootRepository;

final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
    protected array $consumers = [
        SendConfirmationNotification::class,
    ];

    protected string $queue = 'registrations';
}
```

This will force all consumers who have the `ShouldQueue` contract implemented to make use of the `registrations` queue instead of the default queue defined in your `queue.php` config file.

### Consumers

[](#consumers)

Consumers are classes that react to events fired from your aggregate roots. There's two types of consumers: projections and process managers. Projections update read models (think updating data in databases, updating reports,...) while process managers handle one-time tasks (think sending emails, triggering builds, ...). For more information on how to use them, check out EventSauce's [Reacting to Events](https://eventsauce.io/docs/reacting-to-events/setup-consumers/) documentation.

A `SendEmailConfirmation` process manager, for example, can look like this:

```
use App\Events\UserWasRegistered;
use App\Models\User;
use App\Notifications\NewUserNotification;
use EventSauce\LaravelEventSauce\Consumer;

final class SendConfirmationNotification extends Consumer
{
    protected function handleUserWasRegistered(UserWasRegistered $event): void
    {
        User::where('email', $event->email())
            ->first()
            ->notify(new NewUserNotification());
    }
}
```

Within this consumer you always define methods following the `handle{EventName}` specification.

#### Registering Consumers

[](#registering-consumers)

After writing your consumer, you can register them with the `$consumers` property on the related `AggregateRootRepository`:

```
use App\Domain\SendConfirmationNotification;
use EventSauce\LaravelEventSauce\AggregateRootRepository;

final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
    protected array $consumers = [
        SendConfirmationNotification::class,
    ];
}
```

The sequence of adding consumers shouldn't matter as the data handling within these consumers should always be treated as independent from each other.

#### Queueing Consumers

[](#queueing-consumers)

By default, consumers are handled synchronous. To queue a consumer you should implement the `ShouldQueue` contract on your consumer class.

```
use EventSauce\LaravelEventSauce\Consumer;
use Illuminate\Contracts\Queue\ShouldQueue;

final class SendConfirmationNotification extends Consumer implements ShouldQueue
{
    ...
}
```

By doing so, we'll instruct Laravel to queue the consumer and let the data handling be done at a later point in time. This is useful to delay long-running data processing.

Changelog
---------

[](#changelog)

Check out the [CHANGELOG](CHANGELOG.md) in this repository for all the recent changes.

Maintainers
-----------

[](#maintainers)

[This project is currently looking for a new maintainer.](https://github.com/EventSaucePHP/LaravelEventSauce/issues/28)

Acknowledgments
---------------

[](#acknowledgments)

Thanks to [Frank De Jonge](https://twitter.com/frankdejonge) for building [EventSauce](https://eventsauce.io). Thanks to [Freek Van der Herten](https://twitter.com/freekmurze) and [Spatie's Laravel EventSauce library](https://github.com/spatie/laravel-eventsauce) for inspiration to some of the features in this package.

License
-------

[](#license)

Laravel EventSauce is open-sourced software licensed under [the MIT license](LICENSE.md).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~124 days

Total

9

Last Release

1519d ago

PHP version history (3 changes)0.1.0PHP ^7.3

0.2.0PHP ^7.4

0.3.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534693?v=4)[Frank de Jonge](/maintainers/frankdejonge)[@frankdejonge](https://github.com/frankdejonge)

![](https://www.gravatar.com/avatar/21c134451d35d6aed19651f13e2abb56c1dc0eaf7d59c926534c25f072765612?d=identicon)[driesvints](/maintainers/driesvints)

---

Top Contributors

[![driesvints](https://avatars.githubusercontent.com/u/594614?v=4)](https://github.com/driesvints "driesvints (151 commits)")[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (37 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (32 commits)")[![sandervanhooft](https://avatars.githubusercontent.com/u/7265703?v=4)](https://github.com/sandervanhooft "sandervanhooft (4 commits)")[![milroyfraser](https://avatars.githubusercontent.com/u/3282475?v=4)](https://github.com/milroyfraser "milroyfraser (2 commits)")[![Robertbaelde](https://avatars.githubusercontent.com/u/4356288?v=4)](https://github.com/Robertbaelde "Robertbaelde (2 commits)")

---

Tags

event-sourcinglaravelphplaravelevent sourcingEventSauce

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eventsauce-laravel-eventsauce/health.svg)

```
[![Health](https://phpackages.com/badges/eventsauce-laravel-eventsauce/health.svg)](https://phpackages.com/packages/eventsauce-laravel-eventsauce)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[sassnowski/venture

A package to manage complex workflows built on top of Laravel's queue.

825254.5k1](/packages/sassnowski-venture)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
