
Building a Hook System Like WordPress in Laravel with Mksine
One thing I’ve always missed in Laravel applications is a simple way for packages and modules to modify behavior without tightly coupling everything together.
WordPress solved this years ago with Actions and Filters.
So while working on my Laravel + Filament project (Mksine), I decided to implement a hook system inspired by WordPress.
The Problem
As projects grow, adding extension points becomes difficult.
For example:
- A plugin wants to add a menu item.
- A theme wants to modify page output.
- A package wants to inject content into a dashboard widget.
- Another module wants to change data before it’s saved.
Without a hook system, this usually ends up as:
- Event listeners everywhere
- Service container hacks
- Hardcoded integrations
- Direct dependencies between modules
The Approach
I built a lightweight hook manager that supports:
Actions
Execute code at specific points in the application lifecycle.
Hook::addAction('dashboard.render', function () {// Custom logic});
Hook::doAction('dashboard.render');
Filters
Modify values before they are returned.
Hook::addFilter('page.title', function ($title) {return $title . ' - Powered by Mksine';});
$title = Hook::applyFilters('page.title', $title);
Priorities
Multiple hooks can run in a predictable order.
Hook::addAction('menu.register', $callback, 10);
Why Not Just Use Laravel Events?
Laravel events are great.
But events are primarily designed for application workflows.
Hooks provide a more flexible extension layer where plugins and themes can modify behavior without needing explicit knowledge of each other.
For CMS-like systems, this becomes incredibly useful.
What This Enables
With hooks, Mksine can support:
- Plugins
- Themes
- Dynamic menus
- Dashboard extensions
- Page builder integrations
- Media integrations
- Third-party modules
without requiring core modifications.
I’m Curious
Have you implemented a hook/filter system in Laravel before?
If so:
- Did you use Events?
- Custom middleware?
- Something else?
I’d love to hear how others approached extensibility in Laravel applications.