creativesofttechsolutions/laravelhooks
Composer 安装命令:
composer require creativesofttechsolutions/laravelhooks
包简介
Wordpress Like Hooks System Package For Laravel
README 文档
README
This documentation explains how to build and use a flexible and performant hook system in Laravel 12. It supports both actions and filters, similar to WordPress, and works across controllers, Livewire components, middleware, and modules.
🛠 Installation
To install the creativesofttechsolutions/laravelhooks package, use Composer:
composer require creativesofttechsolutions/laravelhooks
🧠 What Are Actions and Filters?
🔹 Actions
- Actions are event triggers.
- They allow you to run additional code when something happens (e.g., after user registration, after an order is placed).
- Actions do not modify any data — they just perform side effects.
hooks()->addAction('after_user_register', function ($user) { Log::info("New user: " . $user->email); });
🔸 Filters
- Filters are used to modify and return data.
- They allow other parts of the application or plugins to intercept, change, or validate values before they are used.
hooks()->addFilter('post_title', function ($title) { return strtoupper($title); });
🚀 Usage Examples
Triggering an action:
hooks()->doAction('after_user_register', $user);
Adding an action (e.g., in a module):
hooks()->addAction('after_user_register', function ($user) { Log::info("User Registered: " . $user->email); });
Adding and using filters:
hooks()->addFilter('product_price', function ($price, $product) { return $product->discount ? $price * 0.9 : $price; }); $price = hooks()->applyFilters('product_price', $originalPrice, $product);
📦 Where to Define Hooks in Modules
In Modules/YourModule/Providers/ModuleServiceProvider.php:
public function boot(): void { hooks()->addAction('after_user_register', ...); hooks()->addFilter('modify_data', ...); }
Or in a dedicated class like:
Modules/YourModule/Hooks/HookRegistrar.php
And load them like:
HookRegistrar::register();
⚙️ Using Hooks in Controllers, Livewire, Middleware
In Controllers:
hooks()->doAction('after_order_created', $order);
In Livewire Components:
$this->value = hooks()->applyFilters('modify_value', $this->value);
In Middleware:
$request = hooks()->applyFilters('modify_request', $request);
✅ Best Practices
- Use meaningful, unique hook names.
- Actions for side effects, Filters for modifying data.
- Use classes instead of closures for better readability and testing.
- Avoid heavy operations inside hook callbacks.
This system brings WordPress-style flexibility to Laravel while preserving Laravel’s clean architecture. You can dynamically extend your app and let plugins interact with core logic cleanly.
creativesofttechsolutions/laravelhooks 适用场景与选型建议
creativesofttechsolutions/laravelhooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 creativesofttechsolutions/laravelhooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 creativesofttechsolutions/laravelhooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-14