Hooks allow third-party code to intervene in the application and make modifications.

0.2.12 2022-07-02 01:49 UTC

This package is auto-updated.

Last update: 2024-04-09 04:22:40 UTC


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