PHPackages                             hongyukeji/laravel-hook - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hongyukeji/laravel-hook

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hongyukeji/laravel-hook
=======================

The WordPress filter/action system in Laravel

v1.1.0(6y ago)32232[1 issues](https://github.com/hongyukeji/laravel-hook/issues)MITPHPPHP &gt;=7.0CI failing

Since Jul 16Pushed 6y ago2 watchersCompare

[ Source](https://github.com/hongyukeji/laravel-hook)[ Packagist](https://packagist.org/packages/hongyukeji/laravel-hook)[ Docs](https://github.com/hongyukeji/laravel-hook)[ RSS](/packages/hongyukeji-laravel-hook/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Hook [![Build Status](https://camo.githubusercontent.com/d188920df54c6abb75718d81eedf1c44bb787e2c95e610e699a7f3bcf92ffe1b/68747470733a2f2f7472617669732d63692e6f72672f686f6e6779756b656a692f6c61726176656c2d686f6f6b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hongyukeji/laravel-hook)
=========================================================================================================================================================================================================================================================================================================

[](#hook-)

Actions and filters in Laravel. WordPress-style.

Hook (for lack of a better name) is a simple action and filter (or hooks if you like) system.

About
-----

[](#about)

Actions are pieces of code you want to execute at certain points in your code. Actions never return anything but merely serve as the option to hook in to your existing code without having to mess things up.

Filters are made to modify entities. They always return some kind of value. By default they return their first parameter and you should too.

[Read more about filters](http://www.wpbeginner.com/glossary/filter/)

[Read more about actions](http://www.wpbeginner.com/glossary/action/)

When would I use Hook?
----------------------

[](#when-would-i-use-hook)

Hook is best used as a way to allow extensibility to your code. Whether you're creating a package or an application, Hook can bring the extensibility you need.

For example, Hook can lay down the foundation for a plugin/module based system. You offer an "action" that allows plugins to register themselves. You might offer a "filter" so plugins can change the contents of an array in the core. You could even offer an "action" so plugins can modify the menu of your application.

Hook is in no way unique in its approach. Laravel provides the Macroable trait that allows you to "hack" in to a class and events so you can act on specific points in your code right out of the box.

Installation
------------

[](#installation)

1. Install using Composer

```
composer require hongyukeji/laravel-hook

```

If you're using Laravel 5.5 or later you can start using the package at this point. Hook is auto-discovered by the Laravel framework.

2. Add the service provider to the providers array in your `config/app.php`.

```
    'Hongyukeji\Hook\HookServiceProvider',
    'Hongyukeji\Hook\HookBladeServiceProvider',
```

3. Add the facade in `config/app.php`

```
    'Hook' => Hongyukeji\Hook\Facades\Hooks::class,
```

Usage
-----

[](#usage)

### Actions

[](#actions)

Anywhere in your code you can create a new action like so:

```
Hook::action('my.hook', 'awesome');
```

The first parameter is the name of the hook; you will use this at a later point when you'll be listening to your hook. All subsequent parameters are sent to the action as parameters. These can be anything you'd like. For example you might want to tell the listeners that this is attached to a certain model. Then you would pass this as one of the arguments.

To listen to your hooks, you attach listeners. These are best added to your `AppServiceProvider` `boot()` method.

For example if you wanted to hook in to the above hook, you could do:

```
Hook::addAction('my.hook', function($what) {
    echo 'You are '. $what;
}, 20, 1);

```

Again the first argument must be the name of the hook. The second would be a callback. This could be a Closure, a string referring to a class in the application container (`MyNamespace\Http\Listener@myHookListener`), an array callback (`[$object, 'method']`) or a globally registered function `function_name`. The third argument is the priority of the hook. The lower the number, the earlier the execution. The fourth parameter specifies the number of arguments your listener accepts.

### Filters

[](#filters)

Filters work in much the same way as actions and have the exact same build-up as actions. The most significant difference is that filters always return their value.

To add a filter:

```
$value = Hook::filter('my.hook', 'awesome');
```

If no listeners are attached to this hook, the filter would simply return `'awesome'`.

This is how you add a listener to this filter (still in the `AppServiceProvider`):

```
Hook::addFilter('my.hook', function($what) {
    $what = 'not '. $what;
    return $what;
}, 20, 1);
```

The filter would now return `'not awesome'`. Neat!

You could use this in conjunction with the previous hook:

```
Hook::addAction('my.hook', function($what) {
    $what = Hook::filter('my.hook', 'awesome');
    echo 'You are '. $what;
});
```

### Using in Blade

[](#using-in-blade)

Given you have added the `HookBladeServiceProvider` to your config, there are two directives available so you can use this in your Blade templates.

Adding the same action as the one in the action example above:

```
@action('my.hook', 'awesome')

```

Adding the same filter as the one in the filter example above:

```
You are @filter('my.hook', 'awesome')

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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 ~296 days

Total

2

Last Release

2198d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/484917e0c99c9779961352578c18bae13504567d6ec43cc3c594b3e447aad436?d=identicon)[hongyukeji](/maintainers/hongyukeji)

---

Tags

eventlaravelwordpresseventsfilterhooksHOOKfiltersactionsaction

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hongyukeji-laravel-hook/health.svg)

```
[![Health](https://phpackages.com/badges/hongyukeji-laravel-hook/health.svg)](https://phpackages.com/packages/hongyukeji-laravel-hook)
```

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)[millat/laravel-hooks

The WordPress filter, action system in Laravel

5715.1k](/packages/millat-laravel-hooks)[x-wp/di

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)

PHPackages © 2026

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