PHPackages                             shooka/laravel-modelevents - 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. shooka/laravel-modelevents

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

shooka/laravel-modelevents
==========================

Let a service provider handle your model events

v0.3.0(9y ago)66.7k2MITPHPPHP &gt;=5.5.0

Since Jan 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/shooka/laravel-modelevents)[ Packagist](https://packagist.org/packages/shooka/laravel-modelevents)[ Docs](https://github.com/shooka/laravel-modelevents)[ RSS](/packages/shooka-laravel-modelevents/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (9)Used By (0)

Laravel ModelEvents
===================

[](#laravel-modelevents)

[![Build Status](https://camo.githubusercontent.com/1018660749b6219f1e80772dc24e0aa00da7cafdf626b58d8445f3bcb3dbd257/68747470733a2f2f7472617669732d63692e6f72672f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/shooka/laravel-modelevents)[![Coverage Status](https://camo.githubusercontent.com/75366056f9e52e65183e38c41bf3032beffbab308ecba0d958a8efe27cb476f4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/shooka/laravel-modelevents?branch=master)[![Total Downloads](https://camo.githubusercontent.com/ec5e0f538eb245eafaeda64846c358fd8bf50a1e53c8be1ae24a42d1e4552848/68747470733a2f2f706f7365722e707567782e6f72672f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732f642f746f74616c2e737667)](https://packagist.org/packages/shooka/laravel-modelevents)[![Latest Stable Version](https://camo.githubusercontent.com/9460bd7e39ec665246e7d937a46fa8bbf3a3ce4c680db922e1599da042a89604/68747470733a2f2f706f7365722e707567782e6f72672f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732f762f737461626c652e737667)](https://packagist.org/packages/shooka/laravel-modelevents)[![Latest Unstable Version](https://camo.githubusercontent.com/24030b4d342db8ed5b0b94c5031e58337a87d825dc9d4dc38ff7c3b5999a27db/68747470733a2f2f706f7365722e707567782e6f72672f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732f762f756e737461626c652e737667)](https://packagist.org/packages/shooka/laravel-modelevents)[![License](https://camo.githubusercontent.com/9ca4d1aab420f28079728a0839e778d30479e0130a3d7ee54530db16f07e35ce/68747470733a2f2f706f7365722e707567782e6f72672f73686f6f6b612f6c61726176656c2d6d6f64656c6576656e74732f6c6963656e73652e737667)](https://packagist.org/packages/shooka/laravel-modelevents)

Have you ever wondered where to put your eloquent model events? It is now easier than ever to apply listeners to your models.

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

[](#installation)

Add this package to your Laravel project by running:

```
composer require shooka/laravel-modelevents 0.3.*
```

To publish the necessary files, add the ServiceProvider to the array of providers in `config/app.php`:

```
Shooka\ModelEvents\ServiceProvider::class,
```

Next, publish the files by running:

```
php artisan vendor:publish --provider="Shooka\ModelEvents\ServiceProvider"
```

This publishes two files:

- A `ModelEvents/UserEvent.php` file that contains a dummy class that shows what future `ModelEvent`s are supposed to look like.
- A `Providers/ModelEventServiceProvider.php` with an empty array of listeners that maps actual Eloquent model events to the `ModelEvent` classes.

As the new `ModelEventServiceProvider` has been published, you can add it to the array of providers:

```
App\Providers\ModelEventServiceProvider::class,
```

> Don't forget to *remove* the original one from the array:
>
> ```
> Shooka\ModelEvents\ServiceProvider::class,
> ```

Usage
-----

[](#usage)

This package is making use of some of the great features of Laravel which means that it is very easy to use in both new and existing Laravel projects.

The events that are supported out of the box are the standard Laravel model events: `creating`, `created`, `updating`, `updated`, `saving`, `saved`, `deleting`, `deleted`, `restoring`, and `restored`

### Custom events

[](#custom-events)

If you want to define any custom events, they should be added to the $observables array:

```
class Product extends Model
{
    protected $observables = [
        'sold',
        'shipped',
        'returned',
        ...
    ];
}
```

Those events are now observable in the `ModelEvent`:

```
class ProductEvent extends ModelEvent
{
    public function returned($product) {
        // Increase stock count
    }
}
```

### Activating a listener

[](#activating-a-listener)

To add a listener to an eloquent model, just map the model to a `ModelEvent` in the `ModelEventServiceProvider`:

```
protected $listeners = [
    \App\Product::class => \App\ModelEvents\ProductEvent::class,
];
```

The `ModelEvent` could be placed anywhere, but is in this example put in the `ModelEvents` folder published by the command from the [Installation](#installation) chapter.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

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

Every ~129 days

Total

3

Last Release

3519d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/38f7b504f3065e9197e5d2b4263f1761de43b92f1f9bb2697eb21961e7e343d2?d=identicon)[shooka](/maintainers/shooka)

---

Top Contributors

[![shooka](https://avatars.githubusercontent.com/u/5556768?v=4)](https://github.com/shooka "shooka (38 commits)")

---

Tags

eventlaraveleventsmodeleloquentlistenerslistenobserve

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shooka-laravel-modelevents/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)

PHPackages © 2026

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