Laravel Hookable is a package that allows you to use hooks (actions and filters) in Laravel applications – similar to the hook system in WordPress.
You can install the package via Composer:
composer require saschaende/laravel-hookableThe package is automatically registered by Laravel (see composer.json).
- Actions: Execute code without modifying data (e.g., for events or extensions).
- Filters: Allow modification of data.
The package provides a Hookable facade that exposes the main methods. The binding is handled automatically via the ServiceProvider.
use SaschaEnde\Hookable\Facades\Hookable;
Hookable::action('my_action', function ($arg1, $arg2) {
// Do something with $arg1 and $arg2
});To execute the action (e.g., at a specific point in your code):
Hookable::renderActions('my_action', $arg1, $arg2);use SaschaEnde\Hookable\Facades\Hookable;
Hookable::filter('my_filter', function ($value) {
// Modify $value
return $value;
});Apply the filter:
$value = Hookable::applyFilters('my_filter', $value);You can specify the priority and the number of arguments for hooks:
Hookable::action('my_action', function ($arg1, $arg2) {
// Do something
}, 20);In this example, the action will be executed with priority 20 and will receive 2 arguments.
The package registers two Blade directives to use hooks directly in Blade templates:
@applyFilter('my_filter', $value)
@doAction('my_action', $arg1, $arg2)@applyFilter('filter_name', $value): Applies a filter to a value and outputs the result.@doAction('action_name', ...): Executes an action and outputs its result.
You can run the tests using PHPUnit:
vendor/bin/phpunitContributions are welcome! Please submit a pull request or open an issue on GitHub.
This package is open-source software licensed under the MIT license.