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

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

jpkleemans/attribute-events
===========================

🔥 Fire events on attribute changes of your Eloquent model

1.5.1(1y ago)332557.7k↓31.3%21[2 issues](https://github.com/jpkleemans/attribute-events/issues)1MITPHPPHP ^7.3|^8.0CI failing

Since Jun 24Pushed 6mo ago5 watchersCompare

[ Source](https://github.com/jpkleemans/attribute-events)[ Packagist](https://packagist.org/packages/jpkleemans/attribute-events)[ Docs](https://attribute.events/)[ GitHub Sponsors](https://github.com/jpkleemans)[ RSS](/packages/jpkleemans-attribute-events/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (13)Used By (1)

[![Laravel Attribute Events](/../gh-pages/attribute-events.svg#gh-light-mode-only)](/../gh-pages/attribute-events.svg#gh-light-mode-only)[![Laravel Attribute Events](/../gh-pages/attribute-events-dark.svg#gh-dark-mode-only)](/../gh-pages/attribute-events-dark.svg#gh-dark-mode-only)

 [![Build Status](https://camo.githubusercontent.com/2597a91cc5b716febbc6aaad6f0e5c5c49df568eb5d955d2d301f187485d582e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6a706b6c65656d616e732f6174747269627574652d6576656e74733f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://app.travis-ci.com/jpkleemans/attribute-events) [![Last Updated](https://camo.githubusercontent.com/9428878f6a3d54a8c12352ebbda4bc27392ca863b026b5c70fe2b2ec22428a99/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6a706b6c65656d616e732f6174747269627574652d6576656e74733f6c6162656c3d75706461746564267374796c653d666c61742d737175617265)](https://github.com/jpkleemans/attribute-events/commits) [![Latest Stable Version](https://camo.githubusercontent.com/eca798bd98aa6f1deca7ce70259605dc0ac6a80e022f35e8086ba4292d224d84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a706b6c65656d616e732f6174747269627574652d6576656e74733f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/jpkleemans/attribute-events) [![License](https://camo.githubusercontent.com/e0f8996d10680690dcaad74a783b56a7dc22fd935f6236ec589d54b11af974f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a706b6c65656d616e732f6174747269627574652d6576656e74733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jpkleemans/attribute-events)

```
class Order extends Model
{
    protected $dispatchesEvents = [
        'status:shipped' => OrderShipped::class,
        'note:*' => OrderNoteChanged::class,
    ];
}
```

Eloquent models fire several handy events throughout their lifecycle, like `created` and `deleted`. However, there are usually many more business meaningful events that happen during a model's life. With this library you can capture those, by mapping attribute changes to your own event classes.

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

[](#installation)

```
composer require jpkleemans/attribute-events
```

How to use it
-------------

[](#how-to-use-it)

Use the `Kleemans\AttributeEvents` trait in your model and add the attributes to the `$dispatchesEvents` property:

```
class Order extends Model
{
    use AttributeEvents;

    protected $dispatchesEvents = [
        'created'         => OrderPlaced::class,
        'status:canceled' => OrderCanceled::class,
        'note:*'          => OrderNoteChanged::class,
    ];
}
```

The attribute events will be dispatched after the updated model is saved. Each event receives the instance of the model through its constructor.

> For more info on model events and the `$dispatchesEvents` property, visit the [Laravel Docs](https://laravel.com/docs/eloquent#events)

Listening
---------

[](#listening)

Now you can subscribe to the events via the `EventServiceProvider` `$listen` array, or manually with Closure based listeners:

```
Event::listen(function (OrderCanceled $event) {
    // Restock inventory
});
```

Or push realtime updates to your users, using Laravel's [broadcasting](https://laravel.com/docs/broadcasting) feature:

```
Echo.channel('orders')
    .listen('OrderShipped', (event) => {
        // Display a notification
    })
```

JSON attributes
---------------

[](#json-attributes)

For attributes stored as JSON, you can use the `->` operator:

```
protected $dispatchesEvents = [
    'payment->status:completed' => PaymentCompleted::class,
];
```

Accessors
---------

[](#accessors)

For more complex state changes, you can use attributes defined by an [accessor](https://laravel.com/docs/eloquent-mutators#defining-an-accessor):

```
class Product extends Model
{
    protected $dispatchesEvents = [
        'low_stock:true' => ProductReachedLowStock::class,
    ];

    public function getLowStockAttribute(): bool
    {
        return $this->stock  You can also use the [new way of defining accessors](https://laravel.com/docs/9.x/releases#eloquent-accessors-and-mutators) introduced in Laravel 9.

Learn more
----------

[](#learn-more)

- [“Decouple your Laravel code using Attribute Events”](https://jpkleemans.medium.com/decouple-your-laravel-code-using-attribute-events-de8f2528f46a) by Jan-Paul Kleemans
- [Laravel Docs on Model Events](https://laravel.com/docs/eloquent#events)

Sponsors
--------

[](#sponsors)

[ ![Nexxtmove Logo](https://raw.githubusercontent.com/jpkleemans/attribute-events/gh-pages/nexxtmove-logo.svg)](https://www.nexxtmove.nl/)Thanks to [Nexxtmove](https://www.nexxtmove.nl/) for sponsoring the development of this project.
Your logo or name here? [Sponsor this project](https://github.com/sponsors/jpkleemans).

License
-------

[](#license)

Code released under the [MIT License](https://github.com/jpkleemans/attribute-events/blob/master/LICENSE).

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance57

Moderate activity, may be stable

Popularity56

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

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

Every ~162 days

Recently: every ~295 days

Total

12

Last Release

458d ago

Major Versions

0.2.0 → 1.0.02020-07-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5700014?v=4)[Jan-Paul Kleemans](/maintainers/jpkleemans)[@jpkleemans](https://github.com/jpkleemans)

---

Top Contributors

[![jpkleemans](https://avatars.githubusercontent.com/u/5700014?v=4)](https://github.com/jpkleemans "jpkleemans (203 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![DennyLoko](https://avatars.githubusercontent.com/u/635014?v=4)](https://github.com/DennyLoko "DennyLoko (1 commits)")[![ariaieboy](https://avatars.githubusercontent.com/u/15873972?v=4)](https://github.com/ariaieboy "ariaieboy (1 commits)")[![ee-bhushan](https://avatars.githubusercontent.com/u/88677237?v=4)](https://github.com/ee-bhushan "ee-bhushan (1 commits)")[![bhushan](https://avatars.githubusercontent.com/u/43483545?v=4)](https://github.com/bhushan "bhushan (1 commits)")[![maartenpaauw](https://avatars.githubusercontent.com/u/4550875?v=4)](https://github.com/maartenpaauw "maartenpaauw (1 commits)")

---

Tags

accessorsattributesddddomain-driven-designdomain-eventsdomain-modeleloquentevent-driven-architectureevent-stormingeventslaravelmodel-eventslaraveleventseloquentattributesddddomain-eventsmodel events

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jpkleemans-attribute-events/health.svg)

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

###  Alternatives

[mvanduijker/laravel-transactional-model-events

Add eloquent model events fired after a transaction is committed or rolled back

75181.9k](/packages/mvanduijker-laravel-transactional-model-events)

PHPackages © 2026

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