PHPackages                             maslauskas/event-store - 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. [Database &amp; ORM](/categories/database)
4. /
5. maslauskas/event-store

ActiveLibrary[Database &amp; ORM](/categories/database)

maslauskas/event-store
======================

Simple event store for Laravel using MySQL

v0.1(8y ago)09051MITPHP

Since Mar 12Pushed 7y ago1 watchersCompare

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

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

event-store
===========

[](#event-store)

Simple EventStore implementation package for Laravel using MySQL.

[![Build Status](https://camo.githubusercontent.com/80a51c105dcad106d58a63fe4818b23fdcf6bfe078859a23193bab631e89d1d7/68747470733a2f2f7472617669732d63692e6f72672f6d61736c6175736b61732f6576656e742d73746f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/maslauskas/event-store) [![Latest Stable Version](https://camo.githubusercontent.com/4fbda1b35e8544e02594b07194349247fc0c27b8eb0f677367af07be03522e27/68747470733a2f2f706f7365722e707567782e6f72672f6d61736c6175736b61732f6576656e742d73746f72652f762f737461626c65)](https://packagist.org/packages/maslauskas/event-store) [![Total Downloads](https://camo.githubusercontent.com/2263761766191119a00e0376d6d657f8d5ae0e05b2b33e8da728fb3dc6f3069e/68747470733a2f2f706f7365722e707567782e6f72672f6d61736c6175736b61732f6576656e742d73746f72652f646f776e6c6f616473)](https://packagist.org/packages/maslauskas/event-store) [![License](https://camo.githubusercontent.com/fb055d56d965e12a4e1812a160224bf64c9e41ffceb7bf823679c13c14ed5dc6/68747470733a2f2f706f7365722e707567782e6f72672f6d61736c6175736b61732f6576656e742d73746f72652f6c6963656e7365)](https://packagist.org/packages/maslauskas/event-store)

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

[](#installation)

To start using this package, install it with composer:

```
composer require maslauskas/event-store
```

Publishing config and migrations:

```
php artisan vendor:publish --provider=Maslauskas\EventStore\EventStoreServiceProvider

```

This package uses Laravel's package auto-discovery feature, so there is no need to modify your `config/app.php` file.

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

[](#configuration)

Event Store logs are saved to your main database by default, but it is recommended to use a dedicated MySQL database for it. Once you create the database, make sure to set Event Store to use it:

First, add a dedicated connection to your `config/database.php` file:

```
'connections' => [

        /*
        ...
        */

        'eventstore' => [
            'driver' => 'mysql',
            'host' => env('EVENT_STORE_HOST', 'localhost'),
            'port' => env('EVENT_STORE_PORT', '3306'),
            'database' => env('EVENT_STORE_DATABASE', 'event_store'),
            'username' => env('EVENT_STORE_USERNAME', 'root'),
            'password' => env('EVENT_STORE_PASSWORD', 'root'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

        /*
        ...
        */
]
```

Next, add required environment variables to your `.env` file:

```
EVENT_STORE_CONNECTION="eventstore"
EVENT_STORE_DATABASE="your_event_store_database_name"
EVENT_STORE_TABLE="your_event_store_table_name"
EVENT_STORE_USERNAME="your_event_store_user_name"
EVENT_STORE_PASSWORD="your_event_store_user_password"
```

It is recommended to create a separate user for event store database, and remove UPDATE, DELETE, DROP permissions, to make sure your event store is append-only.

Next, run the migration to create default event store table:

```
php artisan migrate

```

Usage
-----

[](#usage)

To start logging your events, append this line to your code where you wish the event to be logged:

```
EventStore::add('event_name', $data);
```

Or using the eventstore helper function, which is just a wrapper for the facade:

```
eventstore()->add('event_name', $data);
```

the `add()` method accepts four arguments:

- `$event_type`: name of your event, e.g. `user_created`, `email_sent`, `order_shipped`, etc.
- `$payload`: array of values to record. e.g. for `user_created` event, you can pass the array of attributes that this user was created with.
- `$target_id`: *(optional)* ID of target model in your database. E.g., for `email_sent` event, you can pass `user_id` as `$target_id`. This helps in the future when you wish to fetch all events related to a particular user.
- `$before`: *(optional)* array of values that were changed. E.g. for `user_updated` event, you may pass `$user->toArray()` to record attributes that were changed and their values before the change. *Note:* the `add()` method automatically filters out only those keys that exist in `$payload` parameter to avoid unnecessary overhead.

Sometimes, certain events occur much more frequently than others, e.g. `user_created` and `user_logged_in`. To help with query performance, you can separate certain events to their dedicated tables by changing the `streams` array in `config/eventstore.php` file:

```
'streams' => [
    'user_login_stream' => [
        'user_logged_in',
    ]
]
```

This will automatically create a dedicated `user_login_stream` table in your event store database when you try to add `user_logged_in` event. All events that are not defined in this array will be saved in the default event store table.

Extra methods
-------------

[](#extra-methods)

### query()

[](#query)

Returns `Illuminate\Database\Eloquent\Builder` instance so you can perform any query on event store tables.

### get()

[](#get)

Gets all events from the default event store table. Returns a collection.

### get($event\_name)

[](#getevent_name)

Gets all events of specific type from event store table. Automatically determines which table to search in. Returns a collection.

### stream($stream\_name)

[](#streamstream_name)

Sets dedicated table and returns `Illuminate\Database\Eloquent\Builder` instance so you can perform any query on event store tables.

Exception handling
------------------

[](#exception-handling)

By default, EventStore suppresses any exceptions that occur during `add()` method call. You can disable this by changing `throw_exceptions` setting in `config/eventstore.php`:

```
'throw_exceptions' => true,
```

Testing
-------

[](#testing)

Run the tests with

```
vendor/bin/phpunit

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

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

2980d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2740a0ec368ff98be9e5dbad100ac9f2ee14f86c3f9ed627559f7f4342cd865d?d=identicon)[maslauskas](/maintainers/maslauskas)

---

Top Contributors

[![maslauskas](https://avatars.githubusercontent.com/u/12841532?v=4)](https://github.com/maslauskas "maslauskas (18 commits)")

### Embed Badge

![Health badge](/badges/maslauskas-event-store/health.svg)

```
[![Health](https://phpackages.com/badges/maslauskas-event-store/health.svg)](https://phpackages.com/packages/maslauskas-event-store)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M542](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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