PHPackages                             codecontrol-be/eloquence-hookable - 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. codecontrol-be/eloquence-hookable

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

codecontrol-be/eloquence-hookable
=================================

Laravel Eloquent hooks system.

v8.0.1(1y ago)03.2k↓50%1MITPHPPHP &gt;=8.0

Since Dec 17Pushed 1y agoCompare

[ Source](https://github.com/codecontrol-be/eloquence-hookable)[ Packagist](https://packagist.org/packages/codecontrol-be/eloquence-hookable)[ Fund](https://softonsofa.com)[ GitHub Sponsors](https://github.com/jarektkaczyk)[ RSS](/packages/codecontrol-be-eloquence-hookable/feed)WikiDiscussions master Synced 1mo ago

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

Sofa/Hookable
=============

[](#sofahookable)

[![stable](https://camo.githubusercontent.com/b0c48a65a582755625bf32bb90f262b0384d18804b995382191bd02a3018c09f/68747470733a2f2f706f7365722e707567782e6f72672f66617474757265696e636c6f75642f656c6f7175656e63652d686f6f6b61626c652f762f737461626c652e737667)](https://packagist.org/packages/fattureincloud/eloquence-hookable)

Hooks system for the [Eloquent ORM (Laravel 5.2)](https://laravel.com/docs/5.2/eloquent).

Hooks are available for the following methods:

- `Model::getAttribute`
- `Model::setAttribute`
- `Model::save`
- `Model::toArray`
- `Model::replicate`
- `Model::isDirty`
- `Model::__isset`
- `Model::__unset`

and all methods available on the `Illuminate\Database\Eloquent\Builder` class.

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

[](#installation)

Clone the repo or pull as composer dependency:

```
composer require sofa/hookable:~5.2

```

Usage
-----

[](#usage)

In order to register a hook you use static method `hook` on the model: [example](https://github.com/jarektkaczyk/eloquence/blob/5.1/src/Mappable.php#L42-L56).

**Important** Due to the fact that PHP will not let you bind a `Closure` to your model's instance if it is created **in a static context** (for example model's `boot` method), you need to hack it a little bit, in that the closure is created in an object context.

For example see the above example along with the [class that encloses our closures in an instance scope](https://github.com/jarektkaczyk/eloquence/blob/5.1/src/Mappable/Hooks.php) that is being used there.

Signature for the hook closure is following:

```
function (Closure $next, mixed $payload, Sofa\Hookable\Contracts\ArgumentBag $args)
```

Hooks are resolved via `Sofa\Hookable\Pipeline` in the same order they were registered (except for `setAttribute` where the order is reversed), and each is called unless you return early:

```
// example hook on getAttribute method:
function ($next, $value, $args)
{
    if (/* your condition */) {
        // return early
        return 'some value'; // or the $value
    }

    else if (/* other condition */) {
        // you may want to mutate the value
        $value = strtolower($value);
    }

    // finally continue calling other hooks
    return $next($value, $args);
}
```

Contribution
------------

[](#contribution)

All contributions are welcome, PRs must be **tested** and **PSR-2 compliant**.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.9% 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 ~0 days

Total

2

Last Release

517d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/191989180?v=4)[codecontrol-be](/maintainers/codecontrol-be)[@codecontrol-be](https://github.com/codecontrol-be)

---

Top Contributors

[![jarektkaczyk](https://avatars.githubusercontent.com/u/6928818?v=4)](https://github.com/jarektkaczyk "jarektkaczyk (33 commits)")[![emajo](https://avatars.githubusercontent.com/u/48432054?v=4)](https://github.com/emajo "emajo (4 commits)")[![mattmilesi](https://avatars.githubusercontent.com/u/6038939?v=4)](https://github.com/mattmilesi "mattmilesi (4 commits)")[![EricTendian](https://avatars.githubusercontent.com/u/498525?v=4)](https://github.com/EricTendian "EricTendian (3 commits)")[![boukeversteegh](https://avatars.githubusercontent.com/u/53926?v=4)](https://github.com/boukeversteegh "boukeversteegh (3 commits)")[![rubenlagatie](https://avatars.githubusercontent.com/u/3558417?v=4)](https://github.com/rubenlagatie "rubenlagatie (2 commits)")[![mewebstudio](https://avatars.githubusercontent.com/u/2125733?v=4)](https://github.com/mewebstudio "mewebstudio (2 commits)")[![salkhwlani](https://avatars.githubusercontent.com/u/10876587?v=4)](https://github.com/salkhwlani "salkhwlani (1 commits)")[![itsjavi](https://avatars.githubusercontent.com/u/122741?v=4)](https://github.com/itsjavi "itsjavi (1 commits)")[![jonruttan](https://avatars.githubusercontent.com/u/2718602?v=4)](https://github.com/jonruttan "jonruttan (1 commits)")[![kajetan-nobel](https://avatars.githubusercontent.com/u/3430519?v=4)](https://github.com/kajetan-nobel "kajetan-nobel (1 commits)")[![Remo](https://avatars.githubusercontent.com/u/129864?v=4)](https://github.com/Remo "Remo (1 commits)")

---

Tags

laraveleloquent

### Embed Badge

![Health badge](/badges/codecontrol-be-eloquence-hookable/health.svg)

```
[![Health](https://phpackages.com/badges/codecontrol-be-eloquence-hookable/health.svg)](https://phpackages.com/packages/codecontrol-be-eloquence-hookable)
```

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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