Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Event Sourcing Laravel Package

spatie/laravel-event-sourcing

Event sourcing toolkit for Laravel: build aggregates, projectors, and reactors to store state changes as events. Ideal for audit trails, decisions based on history, and future reporting needs. Includes docs, examples, and an optional course.

View on GitHub
Deep Wiki
Context7

title: Preparing events weight: 1

The package will listen for events that extend the \Spatie\EventSourcing\StoredEvents\ShouldBeStored class. This is an abstract class that signals to the package that the event should be stored.

You can quickly create an event that extends ShouldBeStored by running this artisan command:

php artisan make:storable-event NameOfYourEvent

Here's an example of such event:

namespace App\Events;

use Spatie\EventSourcing\StoredEvents\ShouldBeStored;

class MoneyAdded extends ShouldBeStored
{
    /** [@var](https://github.com/var) string */
    public $accountUuid;

    /** [@var](https://github.com/var) int */
    public $amount;

    public function __construct(string $accountUuid, int $amount)
    {
        $this->accountUuid = $accountUuid;

        $this->amount = $amount;
    }
}

Whenever an event that implements ShouldBeStored is fired it will be serialized and written in the stored_events table. Immediately after that, the event will be passed to all projectors and reactors.

Specifying a queue

When a StoredEvent is created, we'll dispatch a job on the queue defined in the queue key of the event-sourcing config file. Queued projectors and reactors will get called when the job is executed on the queue.

On an event you can override the queue that should be used by adding a queue property.

namespace App\Events;

use Spatie\EventSourcing\StoredEvents\ShouldBeStored;

class MyEvent extends ShouldBeStored
{
    public $queue = 'alternativeQueue';

    ...
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport