PHPackages                             bionicmaster/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. bionicmaster/hookable

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

bionicmaster/hookable
=====================

Laravel Eloquent hooks system.

5.4.1(8y ago)0122MITPHPPHP &gt;=5.6.4

Since Nov 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bionicmaster/hookable)[ Packagist](https://packagist.org/packages/bionicmaster/hookable)[ RSS](/packages/bionicmaster-hookable/feed)WikiDiscussions 5.5 Synced 2mo ago

READMEChangelogDependencies (2)Versions (16)Used By (0)

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

[](#sofahookable)

[![Build Status](https://camo.githubusercontent.com/25c92eabc05472ea43169d88b5e992b98d601cf878b9f135c2e9d6dbffee669a/68747470733a2f2f7472617669732d63692e6f72672f6a6172656b746b61637a796b2f686f6f6b61626c652e737667)](https://travis-ci.org/jarektkaczyk/hookable) [![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

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 66.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 ~48 days

Recently: every ~39 days

Total

15

Last Release

3147d ago

Major Versions

v1.0.2 → v5.12016-01-14

PHP version history (2 changes)v1.0PHP &gt;=5.5.9

v5.3PHP &gt;=5.6.4

### Community

Maintainers

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

---

Top Contributors

[![jarektkaczyk](https://avatars.githubusercontent.com/u/6928818?v=4)](https://github.com/jarektkaczyk "jarektkaczyk (16 commits)")[![boukeversteegh](https://avatars.githubusercontent.com/u/53926?v=4)](https://github.com/boukeversteegh "boukeversteegh (3 commits)")[![bionicmaster](https://avatars.githubusercontent.com/u/312215?v=4)](https://github.com/bionicmaster "bionicmaster (2 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)")

---

Tags

laraveleloquent

### Embed Badge

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

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

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M251](/packages/cviebrock-eloquent-sluggable)[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)

PHPackages © 2026

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