Native Event Sourcing & Temporal Models Support for Laravel #58993
Unanswered
eslam-reda-div
asked this question in
Ideas
Replies: 1 comment 1 reply
-
|
This would be a huge undertaking, so I doubt, Taylor would be willing to take such a step. Luckily, there's a great package called |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'd like to propose introducing first-class, built-in Event Sourcing and Temporal Model support to Laravel's Eloquent ORM.
This feature would allow models to optionally operate in an event-sourced mode, enabling automatic versioning, time-travel queries, and auditability — without relying on third-party packages.
Motivation
Laravel currently stores only the latest state of a model.
When a model is updated:
The previous state is lost unless developers manually implement:
This becomes increasingly complex in domains where:
Event sourcing is a well-established architectural pattern, but Laravel does not natively support it.
This proposal aims to introduce optional, integrated support directly within Eloquent.
Proposed API
1. Aggregate Root Model
Instead of mutating state directly, changes are recorded as domain events.
2. Automatic Event Storage
Events would be stored in a dedicated
event_storetable:| id | aggregate_type | aggregate_id | event_type | payload | version | created_at |
Each model becomes reconstructable via event replay.
3. Temporal Queries
This would allow retrieving model state at a specific point in time or version.
4. Snapshot Support
To avoid replaying thousands of events:
Snapshots would be automatically created to optimize reconstruction performance.
5. Projection System (Optional Read Models)
This allows CQRS-style separation between write and read models.
Implementation Overview
The proposal would introduce:
New Core Classes
New Artisan Commands
Config File
Why Core and Not a Package?
While event sourcing can be implemented via packages, deep integration requires:
A core implementation ensures:
Backward Compatibility
AggregateRootwould use event sourcing.Alternatives Considered
1. Do nothing
Developers can use external packages.
2. Create a community package
Possible, but limited in deep ORM integration.
3. Add versioning only (without full event sourcing)
Simpler, but significantly less powerful.
Questions for the Community
Contribution Plan
If there is interest, I would be happy to:
I’m fully committed to building and maintaining this as a long-term contribution to Laravel.
Looking forward to your feedback.
Beta Was this translation helpful? Give feedback.
All reactions