opensynergic / hooks
Hooks allow third-party code to intervene in the application and make modifications.
0.2.12
2022-07-02 01:49 UTC
Requires
- php: ^8.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
README
Implementation of OJS Hook on Laravel
Installation
Install the package via composer:
composer require opensynergic/hooks
Done, Now you can use hooks
Usage
Wherever you want, you can call a hook in your laravel application.
use OpenSynergic\Hooks\Facades\Hook; Hook::call('user_created', $user);
Here, user_created
is the name of the hook, which will call all the hook registered with the same name. And $user
is the parameters, which will be found whenever you register the new hook with the same name. These can be anything.
To register to your hook, you attach a callback function. These are best added to your AppServiceProvider
boot()
method.
For example if you wanted to hook in to the above hook, you could do:
namespace App\Providers; use Illuminate\Support\ServiceProvider; use OpenSynergic\Hooks\Facades\Hook; use App\Models\User; class AppServiceProvider extends ServiceProvider { //... public function boot(): void { Hook::register('user_created', function($hookName, User $arguments){ $arguments->sendEmailVerificationNotification(); }); } }
Example
More example coming soon