PHPackages                             softonic/laravel-transactional-event-publisher - 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. [API Development](/categories/api)
4. /
5. softonic/laravel-transactional-event-publisher

ActiveLibrary[API Development](/categories/api)

softonic/laravel-transactional-event-publisher
==============================================

Softonic Laravel Transactional Event Publisher

11.0.1(3mo ago)418.8k↓50%Apache-2.0PHPPHP &gt;=8.5CI passing

Since Mar 16Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/softonic/laravel-transactional-event-publisher)[ Packagist](https://packagist.org/packages/softonic/laravel-transactional-event-publisher)[ Docs](https://github.com/softonic/laravel-transactional-event-publisher)[ RSS](/packages/softonic-laravel-transactional-event-publisher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (63)Used By (0)

Laravel Transactional Event Publisher
=====================================

[](#laravel-transactional-event-publisher)

[![Latest Version](https://camo.githubusercontent.com/5d4dc1934b03d3e87f730aa04c8aff297729aec80be99306dc7d841dcb24a691/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](https://github.com/softonic/laravel-transactional-event-publisher/releases)[![Software License](https://camo.githubusercontent.com/36cfc741510e076bec951c1421a2b1c3a5553e953fcdb378339626a5f33c1e8d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/7270c167ec78f7465083c423c61b2f1115d0f0fe02e0e5d0b4122515f9d2d128/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/softonic/laravel-transactional-event-publisher/actions)[![Coverage Status](https://camo.githubusercontent.com/1f70ca52767176282085a87a9ee2859af5bb64e53ddd7d8108aaca4595078285/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/softonic/laravel-transactional-event-publisher/code-structure)[![Quality Score](https://camo.githubusercontent.com/a295293077ffe206071e1ce440d5330c6a900428c936425494936994035ba0e4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/softonic/laravel-transactional-event-publisher)[![Total Downloads](https://camo.githubusercontent.com/dd3cc06b8eed5e6a04188b1d45cc70ee3c79694c33d299ff7e61039f462358a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/softonic/laravel-transactional-event-publisher)[![Average time to resolve an issue](https://camo.githubusercontent.com/ad6b6fdc8e560982b6ea8ae81cfb4422825f8ae59cdbd9e824cfec65967c2c21/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f7265736f6c7574696f6e2f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](http://isitmaintained.com/project/softonic/laravel-transactional-event-publisher "Average time to resolve an issue")[![Percentage of issues still open](https://camo.githubusercontent.com/b2d7576177d961605c8014581a9f9c121bf9416f5d4a51dcac8feda2a8132490/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f6f70656e2f736f66746f6e69632f6c61726176656c2d7472616e73616374696f6e616c2d6576656e742d7075626c69736865722e7376673f7374796c653d666c61742d737175617265)](http://isitmaintained.com/project/softonic/laravel-transactional-event-publisher "Percentage of issues still open")

Laravel package to handle atomicity between Eloquent model operations and domain event message generation.

**Requirements:**

- PHP &gt;= 8.5
- Laravel 12.x

Main features
-------------

[](#main-features)

- Ensure every action has a domain event sent using an atomic transaction between Eloquent model operation, event generation and sent.
- Events sent to a AMQP system sync or async.
- Command to send all the events until now.

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

[](#installation)

You can require the last version of the package using composer

```
composer require softonic/laravel-transactional-event-publisher
```

### Configuration

[](#configuration)

It is possible to configure the basic AMQP information, you can check it in `vendor/softonic/transactional-event-publisher/config/transactional-event-publisher.php`

If you need further customization, you can publish the configuration.

```
php artisan vendor:publish --provider="Softonic\TransactionalEventPublisher\ServiceProvider" --tag=config
```

We provide `Softonic\TransactionalEventPublisher\EventStoreMiddlewares\DatabaseMiddleware`and `Softonic\TransactionalEventPublisher\EventStoreMiddlewares\AmqpMiddleware` middlewares to store and send events.

#### Database middleware

[](#database-middleware)

This middleware just stores the events in a table in database. It can be useful if you want to expose the events as a REST endpoint or check your events history.

To configure this middleware you need to publish the migrations

```
php artisan vendor:publish --provider="Softonic\TransactionalEventPublisher\ServiceProvider" --tag=migrations
```

and execute them

```
php artisan migrate
```

#### Amqp middleware

[](#amqp-middleware)

This middleware publishes the events to an AMQP system. You just need to configure the AMQP connection using the configuration file or environmental variables. As you can see, in the configuration you won't be able to define a queue. This is because the library just publishes the message to an exchange and is the events collector responsibility to declare the needed queues with the needed bindings.

### Publishing events in batches to improve performance

[](#publishing-events-in-batches-to-improve-performance)

We provide a command to continuously publish events in batches. You can find its signature in `Softonic\TransactionalEventPublisher\Console\Commands\EmitEvents`. It will publish the events in batches of 100 by default, or you can change it with the option `--batchSize`. You just need to create a job that will run indefinitely with the command `php artisan event-sourcing:emit`.

#### Sending all the events stored in database

[](#sending-all-the-events-stored-in-database)

By default, the command `php artisan event-sourcing:emit` will send all the events stored in database using a [MySQL unbuffered connection](https://dev.mysql.com/doc/apis-php/en/apis-php-mysqlinfo.concepts.buffering.html). Otherwise, a Mysql buffered Connection it is used to delete the events from database after they have been sent.

You can specify the connection to use with the option `--dbConnection` for the buffered connection and `--dbConnectionUnbuffered` for the unbuffered connection. Unbuffered connection example from `config/database.php`

```
return [
    'connections' => [
        'mysql-unbuffered' => [
            'driver'      => 'mysql',
            'host'        => env('DB_HOST', '127.0.0.1'),
            'port'        => env('DB_PORT', '3306'),
            'database'    => env('DB_DATABASE', 'forge'),
            'username'    => env('DB_USERNAME', 'forge'),
            'password'    => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset'     => 'utf8',
            'collation'   => 'utf8_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
            'options'     => [
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
            ],
        ],
    ]
];
```

### Registering Models

[](#registering-models)

To choose what models should send domain events, you need to attach the `\Softonic\TransactionalEventPublisher\ModelObserver` observer class.

Example:

```
...

use App\Models\Post as MyModel;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Softonic\TransactionalEventPublisher\Observers\ModelObserver;

class EventServiceProvider extends ServiceProvider
{
    public function boot()
    {
        parent::boot();

        MyModel::observe(ModelObserver::class);
    }
    ...
}

```

### Custom middlewares

[](#custom-middlewares)

The middlewares should implement the `Softonic\TransactionalEventPublisher\Interfaces\EventStoreMiddlewareInterface` interface. Its purpose is to store the domain event provided, so you can implement any storage for domain events.

### Custom messages

[](#custom-messages)

The `transactional-event.messageBuilder` class must implement `EventMessageBuilderInterface` and `transactional-event.middleware` class must implement `EventStoreMiddlewareInterface`.

The builder should return a `EventMessageInterface` value object. It just needs to implement the `toArray` and `jsonSerialize` methods with all the attributes that you need.

Considerations
==============

[](#considerations)

This package begins a database transaction in the following Eloquent Model events:

- creating
- updating
- deleting

And commit the database transaction when the event store middleware stores the event message successfully. On the other hand, if the event store couldn't store the event message would be a database rollback for the two operations (Eloquent model write + event message storing). Take into account if an error occurs between the event of creating/updating/deleting and created/updated/deleted the transaction would remain started until the connection had been closed.

Testing
-------

[](#testing)

`softonic/laravel-transactional-event-publisher` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/) following [PSR-12](http://www.php-fig.org/psr/psr-12/).

To run the tests, run the following command from the project folder:

```
$ docker compose run --rm tests
```

To run PHPUnit only:

```
$ docker compose run --rm phpunit
```

To run PHPStan static analysis:

```
$ docker compose run --rm phpstan
```

To check code style:

```
$ docker compose run --rm php composer run checkstyle
```

To fix code style issues:

```
$ docker compose run --rm fixcs
```

To open a terminal in the dev environment:

```
$ docker compose run --rm --entrypoint=bash php
```

For debugging with Xdebug:

```
$ docker compose run --rm debug
```

License
-------

[](#license)

The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance80

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity95

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~57 days

Recently: every ~92 days

Total

51

Last Release

105d ago

Major Versions

6.0.0 → 7.0.02023-07-04

7.0.7 → 8.0.02023-08-11

8.0.1 → 9.0.02023-10-05

9.4.2 → 10.0.02025-01-29

10.2.0 → 11.0.02026-01-14

PHP version history (8 changes)1.0.0PHP &gt;=7.1

2.0.0PHP &gt;=7.2

4.0.0PHP &gt;=7.3

5.0.0PHP &gt;=7.4

5.2.0PHP &gt;=8.0

7.0.0PHP ^8.1

10.0.0PHP ^8.3

11.0.0PHP &gt;=8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/524887?v=4)[Joskfg](/maintainers/Joskfg)[@joskfg](https://github.com/joskfg)

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

---

Top Contributors

[![xaviapa](https://avatars.githubusercontent.com/u/8439057?v=4)](https://github.com/xaviapa "xaviapa (44 commits)")[![Serginyu](https://avatars.githubusercontent.com/u/22319383?v=4)](https://github.com/Serginyu "Serginyu (18 commits)")[![Lotykun-Softonic](https://avatars.githubusercontent.com/u/130476160?v=4)](https://github.com/Lotykun-Softonic "Lotykun-Softonic (11 commits)")[![joskfg](https://avatars.githubusercontent.com/u/524887?v=4)](https://github.com/joskfg "joskfg (11 commits)")[![Lotykun](https://avatars.githubusercontent.com/u/9845202?v=4)](https://github.com/Lotykun "Lotykun (5 commits)")[![josemanuel-cardona](https://avatars.githubusercontent.com/u/196229448?v=4)](https://github.com/josemanuel-cardona "josemanuel-cardona (4 commits)")[![rccrdpccl](https://avatars.githubusercontent.com/u/18526422?v=4)](https://github.com/rccrdpccl "rccrdpccl (3 commits)")[![jeurrutia](https://avatars.githubusercontent.com/u/7116300?v=4)](https://github.com/jeurrutia "jeurrutia (3 commits)")[![bvis](https://avatars.githubusercontent.com/u/580682?v=4)](https://github.com/bvis "bvis (1 commits)")[![paupm](https://avatars.githubusercontent.com/u/85886105?v=4)](https://github.com/paupm "paupm (1 commits)")

---

Tags

laravelevent storecqrssoftonicevent publisher

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/softonic-laravel-transactional-event-publisher/health.svg)

```
[![Health](https://phpackages.com/badges/softonic-laravel-transactional-event-publisher/health.svg)](https://phpackages.com/packages/softonic-laravel-transactional-event-publisher)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[vemcogroup/laravel-weather

Weather package for Laravel to use different providers to get weather info

5525.0k](/packages/vemcogroup-laravel-weather)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

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