Eventy: WordPress-like Actions and Filters for Laravel


June 29th, 2018

Eventy: WordPress-like Actions and Filters for Laravel

Eventy is a Laravel package by Tor Morten Jensen that brings WordPress-style actions and filters to your Laravel app.

This package has a lightweight API and makes it easy to build an action and filter system as found in WordPress. The action and filter system in WordPress is a powerful way to customize WordPress themes without modifying the template. For example, your users could easily tap into the <title></title> tag (think wp_title) to modify the way that title tags work without modifying the template.


Actions are code that you want to enable the ability to tap into code execution at a given point in your code.

Here’s the basic API for creating actions:

1Eventy::action('my.hook', 'awesome');

The best place to add action listeners is in a service provider boot() method:

1public function boot()
3 Eventy::addAction('my.hook', function($what) {
4 echo 'You are '. $what;
5 }, 20, 1);

The Eventy::addAction() method accepts the action name, the callback, the priority, and the number of expected args. The lower the priority number, the earlier the execution.


Like WordPress filters, the Eventy library provides a filter method to modify passed values. Every time a filter is called it returns it’s value after running through various callbacks:

1$value = Eventy::filter('my.hook', 'awesome');

The first argument is the filter name, and the second is the value. If no filter listeners are attached, the return value would be awesome.

The method siguature is the same as actions, including the priority and number of expected arguments:

1Eventy::addFilter('my.hook', function($what) {
2 $what = 'not '. $what;
3 return $what;
4}, 20, 1); // returns `not awesome`

You can even combine actions and filters together:

1Eventy::addAction('my.hook', function($what) {
2 $what = Eventy::filter('my.hook', 'awesome');
3 echo 'You are '. $what;


Using the same examples from the project’s readme, here’s what the template syntax looks like for this package:

1{{-- for example, `echo "awesome"` --}}
2@action('my.hook', 'awesome')
4You are @filter('my.hook', 'awesome')

Learn More

You can learn more about Eventy from the project’s GitHub repository and install it with composer require tormjens/eventy.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.