2017 © Pedro Peláez
 

library hookable

Laravel Eloquent hooks system.

image

sofa/hookable

Laravel Eloquent hooks system.

  • Saturday, March 3, 2018
  • by jarektkaczyk
  • Repository
  • 3 Watchers
  • 34 Stars
  • 302,651 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 24 Forks
  • 2 Open issues
  • 20 Versions
  • 13 % Grown

The README.md

Sofa/Hookable

GitHub Tests Action Status stable Downloads, (*1)

Hooks system for the Eloquent ORM (Laravel 5.2)., (*2)

Hooks are available for the following methods:, (*3)

  • 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., (*4)

Installation

Clone the repo or pull as composer dependency:, (*5)

composer require sofa/hookable:~5.2

Usage

In order to register a hook you use static method hook on the model: example., (*6)

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., (*7)

For example see the above example along with the class that encloses our closures in an instance scope that is being used there., (*8)

Signature for the hook closure is following:, (*9)

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:, (*10)

// 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

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

The Versions

03/03 2018

5.6.x-dev

5.6.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

03/03 2018

5.6

5.6.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

17/11 2017

5.5.x-dev

5.5.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

17/11 2017

v5.5.1

5.5.1.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

13/10 2017

v5.5

5.5.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

26/09 2017

dev-master

9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

26/09 2017

5.4.x-dev

5.4.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

27/05 2017

5.4.1

5.4.1.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

22/04 2017

5.3.x-dev

5.3.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

22/04 2017

5.4

5.4.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

08/11 2016

5.2.x-dev

5.2.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

26/08 2016

V5.3.1

5.3.1.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

22/08 2016

v5.3

5.3.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

14/01 2016

5.1.x-dev

5.1.9999999.9999999-dev

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

14/01 2016

v5.1.1

5.1.1.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

14/01 2016

v5.2

5.2.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

14/01 2016

v5.1

5.1.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent

17/11 2015

v1.0.2

1.0.2.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

laravel eloquent

17/11 2015

v1.0.1

1.0.1.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

laravel eloquent

17/11 2015

v1.0

1.0.0.0

Laravel Eloquent hooks system.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

laravel eloquent