masterbroki / hookable
Laravel Eloquent hooks system.
Installs: 31
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 69
Open Issues: 0
pkg:composer/masterbroki/hookable
Requires
- php: ^8.0
- illuminate/database: ^10.11
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^10.0
README
This is a overhaul of the Hookable system from jarektkaczyk/hookable to support laravel 10 and make the system leaner.
Hooks system for the Eloquent ORM (Laravel 10.0).
Hooks are available for the following methods:
Model::getAttributeModel::setAttributeModel::saveModel::toArrayModel::replicateModel::isDirtyModel::__issetModel::__unset
and all methods available on the Illuminate\Database\Eloquent\Builder class.
Installation
Clone the repo or pull as composer dependency:
composer require masterbroki/hookable:~10.0
Usage
Use the hookable trait on the model:
class MyModel extends \Illuminate\Database\Eloquent\Model{ use Sofa\Hookable\Hookable; }
In order to register a hook, use the static method hook on the model:
MyModel::hook('myMethod', function($myParams){ return "I want to select: " . implode(', ', $myParams); });
And when the attribute is called:
$result = MyModel::select(["first", "second"]); // $result will equal "I want to select: first, second"
Contribution
All contributions are welcome, PRs must be tested.