PHPackages                             phutureproof/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. [Framework](/categories/framework)
4. /
5. phutureproof/hookable

ActiveLibrary[Framework](/categories/framework)

phutureproof/hookable
=====================

Laravel Eloquent hooks system.

06PHP

Since Feb 1Pushed 3y agoCompare

[ Source](https://github.com/phutureproof/hookable)[ Packagist](https://packagist.org/packages/phutureproof/hookable)[ RSS](/packages/phutureproof-hookable/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#sofahookable)

[![GitHub Tests Action Status](https://github.com/jarektkaczyk/hookable/workflows/Tests/badge.svg)](https://github.com/jarektkaczyk/hookable/actions?query=workflow%3Atests+branch%3Amaster) [![stable](https://camo.githubusercontent.com/2a86dcf9649a4049532d6244ef1e29ae075a4b0f67818a545ba540fff3b1bc9a/68747470733a2f2f706f7365722e707567782e6f72672f736f66612f686f6f6b61626c652f762f737461626c652e737667)](https://packagist.org/packages/sofa/hookable) [![Downloads](https://camo.githubusercontent.com/4150d2506de3a47f2e5c82e5598d939efb515366a4e4705f3b1d22feadf0c3dd/68747470733a2f2f706f7365722e707567782e6f72672f736f66612f686f6f6b61626c652f646f776e6c6f616473)](https://packagist.org/packages/sofa/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

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 71.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/119378bb231320e2dfa58326842f42f9b2666a920a5c44be41c9e2c8079e2d6b?d=identicon)[PhutureProof](/maintainers/PhutureProof)

---

Top Contributors

[![jarektkaczyk](https://avatars.githubusercontent.com/u/6928818?v=4)](https://github.com/jarektkaczyk "jarektkaczyk (33 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)")[![mewebstudio](https://avatars.githubusercontent.com/u/2125733?v=4)](https://github.com/mewebstudio "mewebstudio (2 commits)")[![Remo](https://avatars.githubusercontent.com/u/129864?v=4)](https://github.com/Remo "Remo (1 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)")

### Embed Badge

![Health badge](/badges/phutureproof-hookable/health.svg)

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M299](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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