A client asks "why did this order's status go from preparing to cancelled yesterday at 2:32pm, and who did it?" The orders table only holds the final state: status = 'cancelled'. No trace of the transition, no trace of who triggered it. Building full event sourcing (event store, projections, replay) just to answer that question would be overkill. The right-sized answer is lightweight event sourcing: capture meaningful business events through Laravel's Events, without throwing away the existing relational model.
The concrete problem
"Full" event sourcing replaces the source of truth: instead of storing current state, you store the sequence of events that led to it, and current state becomes a projection recomputed from that sequence. It's powerful, but it radically changes the architecture (a dedicated event store, event schema versioning, state reconstruction via replay), and it's rarely justified for a typical business application. What you often actually want is more modest: keep the regular Eloquent model as the source of truth, but faithfully capture every important business transition in a queryable log, for audit purposes, customer support, and sometimes to trigger side effects (notifications, billing, webhooks).
Modeling the business event, not the technical event
The first mistake is conflating "Laravel event" (the technical mechanism: Event::dispatch()) with "business event" (the fact worth recording: order cancelled, payment confirmed, stock adjusted). A well-modeled business event carries a past-tense name, an aggregate identifier, and enough context to understand what happened without having to reload the full state.
// app/Events/OrderCancelled.php
namespace App\Events;
use App\Models\Order;
use Illuminate\Foundation\Events\Dispatchable;
class OrderCancelled
{
use Dispatchable;
public function __construct(
public readonly Order $order,
public readonly string $reason,
public readonly ?int $cancelledByUserId,
public readonly string $previousStatus,
) {}
}
The model fires the event at the moment of the transition, not after the fact in some cleanup job:
// app/Models/Order.php
public function cancel(string $reason, ?int $byUserId = null): void
{
$previousStatus = $this->status;
$this->update(['status' => OrderStatus::Cancelled]);
event(new OrderCancelled(
order: $this,
reason: $reason,
cancelledByUserId: $byUserId,
previousStatus: $previousStatus,
));
}
The event log: the table that answers audit questions
A dedicated Listener persists every business event into an event_log table, independently of the model's current state:
// app/Listeners/PersistDomainEvent.php
namespace App\Listeners;
use App\Models\EventLog;
class PersistDomainEvent
{
public function handle(object $event): void
{
EventLog::create([
'aggregate_type' => get_class($event->order),
'aggregate_id' => $event->order->id,
'event_type' => class_basename($event),
'payload' => [
'reason' => $event->reason ?? null,
'previous_status' => $event->previousStatus ?? null,
'cancelled_by_user_id' => $event->cancelledByUserId ?? null,
],
'occurred_at' => now(),
]);
}
}
// EventServiceProvider, or bootstrap/app.php (Laravel 11+)
protected $listen = [
\App\Events\OrderCancelled::class => [
\App\Listeners\PersistDomainEvent::class,
\App\Listeners\NotifyCustomerOfCancellation::class,
],
];
-- migration
CREATE TABLE event_log (
id BIGSERIAL PRIMARY KEY,
aggregate_type VARCHAR(255) NOT NULL,
aggregate_id BIGINT NOT NULL,
event_type VARCHAR(255) NOT NULL,
payload JSONB NOT NULL,
occurred_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_event_log_aggregate ON event_log (aggregate_type, aggregate_id, occurred_at);
Now "why and by whom" is a straightforward query:
SELECT event_type, payload, occurred_at
FROM event_log
WHERE aggregate_type = 'App\\Models\\Order' AND aggregate_id = 4821
ORDER BY occurred_at ASC;
A separate Listener for persistence (rather than inserting directly inside the model) keeps the business model clean and lets you add or remove side effects (notifications, billing) without touching the state-transition logic itself.
Observers: capturing what the code "forgets" to trigger
Explicit Events capture transitions that the business logic triggers intentionally. But a direct Eloquent update (Order::find($id)->update(['status' => 'cancelled']) in a maintenance script, a batch job, or a poorly written controller that bypasses the cancel() method) never goes through that path. Laravel Observers fill that gap by hooking directly into Eloquent's lifecycle events:
// app/Observers/OrderObserver.php
namespace App\Observers;
use App\Models\Order;
use App\Models\EventLog;
class OrderObserver
{
public function updated(Order $order): void
{
if ($order->wasChanged('status')) {
EventLog::create([
'aggregate_type' => Order::class,
'aggregate_id' => $order->id,
'event_type' => 'OrderStatusChanged',
'payload' => [
'from' => $order->getOriginal('status'),
'to' => $order->status,
],
'occurred_at' => now(),
]);
}
}
}
// app/Providers/AppServiceProvider.php
public function boot(): void
{
Order::observe(OrderObserver::class);
}
This safety net catches every status change, even ones that bypass the dedicated business method. The tradeoff is that it loses the rich context (reason, actor) that only the intentional caller knows about: it's a compromise between exhaustive coverage and information richness, not a replacement for explicit Events.
Making persistence reliable: queued listeners and failure handling
A common trap in this approach is treating log persistence as a secondary detail, when it should be at least as reliable as the business write itself. By default, a Laravel Listener runs synchronously, in the same request as the business transition: if the connection to the log's database is briefly unavailable, the exception bubbles up and can fail the entire request, including the business transition that has nothing to do with the logging problem.
The standard fix is making the Listener asynchronous via a queue, by implementing ShouldQueue:
// app/Listeners/PersistDomainEvent.php
namespace App\Listeners;
use App\Models\EventLog;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class PersistDomainEvent implements ShouldQueue
{
use InteractsWithQueue;
public int $tries = 5;
public int $backoff = 10;
public function handle(object $event): void
{
EventLog::create([
'aggregate_type' => get_class($event->order),
'aggregate_id' => $event->order->id,
'event_type' => class_basename($event),
'payload' => [
'reason' => $event->reason ?? null,
'previous_status' => $event->previousStatus ?? null,
],
'occurred_at' => now(),
]);
}
public function failed(object $event, \Throwable $exception): void
{
// Explicit alert: a gap in the audit log is an incident,
// not just a silently failed job
report($exception);
Log::critical('Failed to persist a domain event', [
'event' => class_basename($event),
'order_id' => $event->order->id ?? null,
]);
}
}
This decoupling has a cost: the business transition (the update() on the order) and the log write are no longer atomic within the same transaction. A queue worker crash between the transition and the job's processing can, in rare cases, leave a transition with no trace in the log. For a strict audit requirement (financial sector, regulated industry), the right answer is often a hybrid approach: write the log row within the same SQL transaction as the business transition itself (a synchronous Listener, inside the transaction), and reserve the queue for side effects that can tolerate a delay (an email notification, an outgoing webhook).
public function cancel(string $reason, ?int $byUserId = null): void
{
DB::transaction(function () use ($reason, $byUserId) {
$previousStatus = $this->status;
$this->update(['status' => OrderStatus::Cancelled]);
// Synchronous log write in the SAME transaction:
// either both writes succeed, or neither does.
EventLog::create([
'aggregate_type' => static::class,
'aggregate_id' => $this->id,
'event_type' => 'OrderCancelled',
'payload' => ['reason' => $reason, 'previous_status' => $previousStatus],
'occurred_at' => now(),
]);
});
// Non-critical side effects (notifications) stay on the queue,
// outside the transaction.
event(new OrderCancelled($this, $reason, $byUserId, $previousStatus));
}
Diagnosing coverage gaps
To verify the log actually captures every critical transition, the right move is auditing every write path that touches the field in question:
grep -rn "status.*=.*cancelled\|update(\['status'" app/ --include="*.php"
Every hit that goes through neither the cancel() method nor an Observer covering that model is a gap in the audit trail. That's typically where "how did this even change without anyone knowing" incidents hide in production.
When this approach isn't enough
If the business need evolves toward reconstructing past state (knowing exactly what an order looked like at any point in time, not just its last transition), or toward multiple projections derived independently from the same stream of events (a finance dashboard and a logistics dashboard both recomputed from the same events), that's the signal to move to a real event store with replay and event schema versioning, likely with a dedicated package such as spatie/laravel-event-sourcing rather than hand-rolling more complexity into this lightweight pattern.
Takeaway
Lightweight event sourcing with Laravel Events and Observers delivers most of the audit value of full event sourcing (transition traceability, business context, side-effect triggering) for a fraction of the architectural complexity, provided you explicitly audit the write paths that bypass your business methods. It is not a real event store: current state remains the source of truth, and the log is queryable for reading, not replayable to reconstruct state.
