PHPackages                             jooservices/laravel-events - 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. jooservices/laravel-events

ActiveLibrary

jooservices/laravel-events
==========================

EventSourcing and EventLog for Laravel with MongoDB storage

1.0.0(2mo ago)00MITPHPPHP ^8.5

Since Mar 9Pushed 2mo agoCompare

[ Source](https://github.com/jooservices/laravel-events)[ Packagist](https://packagist.org/packages/jooservices/laravel-events)[ RSS](/packages/jooservices-laravel-events/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Laravel Events
==============

[](#laravel-events)

EventSourcing and EventLog for Laravel with **MongoDB** storage. Store domain event payloads by aggregate and/or model change audit trails (prev/changed/diff) via Laravel's event dispatcher.

- **Laravel 12** · **PHP 8.5+**
- **MongoDB** via [mongodb/laravel-mongodb](https://github.com/mongodb/laravel-mongodb)

---

Introduction
------------

[](#introduction)

This package adds two persistence features on top of Laravel's event system:

1. **Event Sourcing** — Events implementing `EventSourcingInterface` are stored in a `stored_events` MongoDB collection (payload, aggregate id, metadata, user, time). Use for event replay, analytics, or audit by aggregate.
2. **Event Log** — Events implementing `LoggableModelInterface` are stored in an `event_logs` collection with previous/changed state and a per-field diff. Use for audit trails and compliance.

You dispatch events as usual; package subscribers persist them to MongoDB. No custom bus or queue required.

---

Quick Start
-----------

[](#quick-start)

### Install

[](#install)

```
composer require jooservices/laravel-events
```

### Publish config (optional)

[](#publish-config-optional)

```
php artisan vendor:publish --tag=laravel-events-config
```

### Environment

[](#environment)

```
MONGODB_URI=mongodb://127.0.0.1:27017
MONGODB_DATABASE=your_db
EVENTS_EVENTSOURCING_ENABLED=true
EVENTS_EVENT_LOG_ENABLED=true
```

Ensure a `mongodb` connection exists in `config/database.php` (see [mongodb/laravel-mongodb](https://github.com/mongodb/laravel-mongodb)).

### Indexes

[](#indexes)

```
php artisan events:install-indexes
```

---

Basic Usage
-----------

[](#basic-usage)

### Event Sourcing

[](#event-sourcing)

Implement `EventSourcingInterface` and dispatch:

```
use JooServices\LaravelEvents\EventSourcing\Contracts\EventSourcingInterface;

class OrderCreated implements EventSourcingInterface
{
    public function __construct(public string $orderId, public array $items) {}

    public function payload(): array
    {
        return ['order_id' => $this->orderId, 'items' => $this->items];
    }

    public function aggregateId(): ?string
    {
        return $this->orderId;
    }
}

event(new OrderCreated('ORD-001', [['sku' => 'X', 'qty' => 2]]));
```

Events are stored in the `stored_events` collection. Optional: `occurredAt(): ?\Carbon\CarbonInterface`, `metadata(): array`. Use the `HasEventSourcingDefaults` trait to implement only `payload()` and `aggregateId()`.

### Event Log (Audit)

[](#event-log-audit)

Implement `LoggableModelInterface` (and optionally `HasLogAction`) and dispatch with prev/changed state. Use the `DefaultsToUpdatedAction` trait when the action is always `updated`:

```
use JooServices\LaravelEvents\EventLog\Concerns\DefaultsToUpdatedAction;
use JooServices\LaravelEvents\EventLog\Contracts\LoggableModelInterface;
use JooServices\LaravelEvents\EventLog\Contracts\HasLogAction;

class OrderUpdated implements LoggableModelInterface, HasLogAction
{
    use DefaultsToUpdatedAction;

    public function __construct(public Order $model, public array $prev) {}

    public function getLoggableType(): string { return $this->model->getMorphClass(); }
    public function getLoggableId(): string { return (string) $this->model->getKey(); }
    public function getPrev(): array { return $this->prev; }
    public function getChanged(): array { return $this->model->getAttributes(); }
}
```

Changes are stored in `event_logs` with a computed diff. Query by `entity_type` + `entity_id`.

---

Documentation
-------------

[](#documentation)

Full documentation is in the **`./docs`** folder:

DocumentDescription[docs/README.md](docs/README.md)Documentation index[Architecture](docs/architecture.md)Design, data flow, diagrams[Code structure](docs/code-structure.md)Package layout and namespaces[Installation](docs/installation.md)Requirements and setup[Configuration](docs/configuration.md)Config and context provider[Event Sourcing](docs/event-sourcing.md)Stored events and aggregates[Event Log](docs/event-log.md)Audit trail and diff[Samples](docs/samples.md)Complete code examples[API Reference](docs/api.md)EventService, interfaces, commands---

Testing &amp; Linting
---------------------

[](#testing--linting)

```
composer test
composer lint   # Pint, PHPStan, PHPMD, PHPCS
```

---

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance87

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

65d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4ff5b64fb70623808dbe8a32cabfd3add7db11ee382893a437c2660ba9d9f55?d=identicon)[jooservices](/maintainers/jooservices)

---

Top Contributors

[![soulevilx](https://avatars.githubusercontent.com/u/2688707?v=4)](https://github.com/soulevilx "soulevilx (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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