artisanpack-ui/hooks
WordPress-style actions and filters for Laravel. Register callbacks on named hooks and filter values with helper functions, Facades, and Blade directives. Predictable priority order, auto-discovery, and support for removing specific or all callbacks.
@action, @filter) enable template-level extensibility, reducing the need for complex view composers or service injection in views.config/app.php edits, reducing deployment friction.| Risk Area | Mitigation Strategy |
|---|---|
| Performance Overhead | Benchmark doAction/applyFilters in high-throughput systems (e.g., 100+ callbacks). Consider lazy-loading hooks or priority-based batching. |
| Callback Leaks | Use removeAction/removeFilter to avoid memory leaks in long-running processes (e.g., queues). Monitor with Laravel’s debugbar or tntsearch/laravel-query-cache. |
| Priority Conflicts | Document priority ranges (e.g., 0–10 for core, 10–20 for plugins) to prevent "callback hell." |
| Blade Security | Sanitize @filter outputs in Blade to avoid XSS (e.g., wrap with e() or htmlspecialchars). |
| Version Locking | Pin to ^1.2 in composer.json to avoid auto-updates during minor releases. |
doAction results.Action::do()) or implicit functions (e.g., doAction())?auth.login, payment.process) to avoid collisions?deprecated() in callbacks to warn users.)resources/boost/) can auto-generate hook examples or validate hook usage.kebab-case).| Current Pattern | Migration Strategy |
|---|---|
| Observers | Replace Observing with addAction('model.saved', ...) for simpler callbacks. |
| Middleware | Use addAction('kernel.handle', ...) for HTTP-level hooks (but middleware is still better for auth/CSRF). |
| Service Container Bindings | Replace bind() for dynamic behavior with addFilter('value.transform', ...). |
| Custom Events | Convert to hooks if events are synchronous and modular (e.g., Event::dispatch() → doAction('event.name')). |
| View Composers | Replace with @action('view.render', $data) in Blade for dynamic view logic. |
config/app.php edits).addAction('package.event')).@filter('user.display_name', $user)).addAction('order.process', ..., 5) for early validation).removeAction) to clean up callbacks in queued jobs or API gateways.HooksServiceProvider) makes it easy to list all hooks (Action::getHooks() if exposed).php artisan make:hook or a custom hooks.json manifest).deprecated() in callbacks to warn users before removing hooks.addAction('legacy.hook', function () {
deprecated('legacy.hook', '2025-01-01');
// ...
});
Action::fake() (if supported) or partial mocking.Action::shouldReceive('do')->with('test.hook')->once();
doAction('debug.hook', $data) and a dedicated DebugAction listener.tap() to inspect filter values:
$value = applyFilters('data.process', $value)->tap(fn ($v) => logger("Filtered: $v"));
Xdebug or tighten/laravel-query-cache.doAction('user.load') with 50+ callbacks.removeAllActions() in terminating middleware or queue workers.How can I help you explore Laravel packages today?