PHPackages                             pektiyaz/laravel-event-engine - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pektiyaz/laravel-event-engine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pektiyaz/laravel-event-engine
=============================

Event Driven Core for laravel applications

v1.0.0(1y ago)0135MITPHP

Since Apr 9Pushed 10mo ago1 watchersCompare

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

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

EventEngine for Laravel
=======================

[](#eventengine-for-laravel)

EventEngine is a powerful and declarative extension for Laravel’s event system, providing a clear can → do → after pattern for modular business logic.

Installation
============

[](#installation)

```
composer require pektiyaz/laravel-event-engine
```

Features
========

[](#features)

Method Description
------------------

[](#methoddescription)

- can() Checks if the action is allowed before proceeding
- do() Performs an action and expects a success/failure response
- doAtomic() Performs an action inside a DB transaction (rollback-safe)
- after() Fires events that don’t affect control flow

Listener Contracts
==================

[](#listener-contracts)

can(...) listeners:
-------------------

[](#can-listeners)

Must return:

```
return new EventCanValue(true)
// OR
return new EventCanValue(true, $data)
// OR
return new EventCanValue(false, "Reason..")
```

do(...) listeners:
------------------

[](#do-listeners)

Must return:

```
return new EventDoValue(true)
// OR
return new EventDoValue(true, $data)
// OR
return new EventDoValue(false, "Reason...")
```

ask(...) listeners:
-------------------

[](#ask-listeners)

Must return:

```
//Listener in module Account
return new EventAskValue(true, ["name" => "John"])

//Listener in module Finance
return new EventAskValue(true, ["balance" => 500])

//Result
[
    "name" => "John",
    "balance" => 500
]
```

after(...) listeners:
---------------------

[](#after-listeners)

Should not return anything. These may implement ShouldQueue.

Setup
=====

[](#setup)

Create an event and a listener for can(), do(), or after() patterns.

Register the listener in Laravel (EventServiceProvider).

1. Create an Event
------------------

[](#1-create-an-event)

Example: CanClientPay

```
namespace App\Events;

class CanClientPay
{
    public function __construct(
        public int   $clientId,
        public float $amount
    ) {}
}
```

2. Create a Listener
--------------------

[](#2-create-a-listener)

Listener that handles this event and returns a EventCanValue response.

```
namespace App\Listeners;

use App\Events\CanClientPay;use Pektiyaz\LaravelEventEngine\CanValues\EventCanValue;

class CheckClientBalanceListener
{
    public function handle(CanClientPay $event): EventCanValue
    {
        // Example logic: client can pay if they have more than $event->amount
        $balance = 500; // You’d normally fetch this from DB

        if ($balance >= $event->amount) {
            return new EventCanValue(true);
        }

        return new EventCanValue(false, 'Insufficient balance');
    }
}
```

Note: Always return an array from the listener (for can() and do() usage).

3. Register the Listener
------------------------

[](#3-register-the-listener)

Open app/Providers/EventServiceProvider.php and add your event + listener:

```
protected $listen = [
    \App\Events\CanClientPay::class => [
        \App\Listeners\CheckClientBalanceListener::class,
    ],
];
```

Then run:

```
php artisan event:clear
php artisan event:cache
```

Usage Examples
==============

[](#usage-examples)

can() — check permission
------------------------

[](#can--check-permission)

```
use App\Support\EventEngine;
use App\Events\CanClientPay;

$result = EventEngine::can(new CanClientPay($clientId, $amount));

if (!$result->can) {
    // Listing all answers
    foreach ($result->answers as $answer) {
        //$answer->can
        //$answer->data
        //$answer->toArray()
        Log::debug('Event Answer', $answer->toArray());
    }
    //$result->toArray()
    return response()->json(['error' => 'Payment denied', 'details' => $result->data]);
}
```

do() — execute an action
------------------------

[](#do--execute-an-action)

```
use App\Events\ClientProcessPay;

$process = EventEngine::do(new ClientProcessPay($clientId, $amount));

if (!$process->success) {
    // Listing all answers
    foreach ($result->answers as $answer) {
        //$answer->success
        //$answer->data
        //$answer->toArray()
        Log::debug('Event Answer', $answer->toArray());
    }
    //$result->toArray()
    return response()->json(['error' => 'Payment failed', 'details' => $process->data]);
}

return response()->json(['message' => 'Payment success', 'data' => $process->data]);
```

doAtomic() — run EventEngine::do in DB transaction
--------------------------------------------------

[](#doatomic--run-eventenginedo-in-db-transaction)

```
$response = EventEngine::doAtomic(new ClientPaid($clientId, $amount));

if (!$response->success) {
    return response()->json([
        'error' => 'Transaction rolled back',
        'details' => $response->data,
    ]);
}
```

after() — fire an event without expecting a response
----------------------------------------------------

[](#after--fire-an-event-without-expecting-a-response)

```
use App\Events\ClientPaid;

EventEngine::after(new ClientPaid($clientId, $amount));
```

ask() — collect data from listeners and returning array of answers
------------------------------------------------------------------

[](#ask--collect-data-from-listeners-and-returning-array-of-answers)

```
use App\Events\GetUserInfo;

$process = EventEngine::ask(new GetUserInfo($clientId));
if($process->success){
    return response()->json([
        'user' => $response->data,
    ]);
}
```

With Listener name
==================

[](#with-listener-name)

```
namespace App\Listeners;

use App\Events\CanClientPay;use Pektiyaz\LaravelEventEngine\CanValues\EventCanValue;

class CanClientPayListener
{
    public function handle(CanClientPay $event): EventCanValue
    {
        // Example logic: client can pay if they have more than $event->amount
        $balance = 500; // You’d normally fetch this from DB

        if ($balance >= $event->amount) {
            return new EventCanValue(true);
        }

        return new EventCanValue(false, 'Insufficient balance', "CanClientPayListener");
    }
}
```

```
$result = EventEngine::can(new CanClientPay($clientId, $amount));
foreach($result->answers as $answer){
    $answer->listener // CanClientPayListener
}
```

Why use EventEngine?
====================

[](#why-use-eventengine)

- Clear separation of responsibilities (can, do, after)
- Easy to test and maintain
- Decouples business logic from the framework
- Centralized event orchestration
- Scales well with modular systems

Coming Soon (ideas)
===================

[](#coming-soon-ideas)

- Configurable behavior via config file
- failFast and collectAllErrors options
- Automatic event registration
- Publishable Laravel package with service provider

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance51

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

398d ago

### Community

Maintainers

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

---

Top Contributors

[![pektiyaz](https://avatars.githubusercontent.com/u/30262879?v=4)](https://github.com/pektiyaz "pektiyaz (8 commits)")

### Embed Badge

![Health badge](/badges/pektiyaz-laravel-event-engine/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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