1. Go to this page and download the library: Download coinvestor/larahook library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Hook::get(
string $hook, // Name of the hook to run
array $params, // Array of values to be passed to the listeners on this hook.
callable $callback, // Callback method to return default value if no listeners are registered.
bool $useCallbackAsFirstListener // Should the default callback be run and used as the first $output value
// for the listeners. Defaults to false.
);
Hook::listen(
string $hook, // Name of the hook to listen on.
callable $method ( // Callback to execute when hook is run.
callable $callback, // Default callback from the `get`. Called as `$callback->call`
mixed $output, // Output from previous hook. Will be null unless useCallbackAsFirstListener
// is set to true, in which case it will be the default callbacks value.
mixed $arg1, // Each value provided to the `get` methods params array, is added to the
mixed $arg2, // callbacks arguments in the order they were added.
)
int $priority // Used the control when each listener runs. The higher this value, the later it will run in the list of listeners on the hook.
);
Hook::get('testing', ['Delilah'], function ($testString) {
return 'Hi ' . $testString;
}, true)
// and later ...
Hook::listen('testing', function ($callback, $output, $name) {
if ($output === 'Hi Delilah') {
$output = "{$output}. Whats up!";
} else {
$output = "{$output}. Welcome back.";
}
return $output; // 'Hi Delilah. Whats up!'
});
@hook('hookName')
Hook::listen('template.hookName', function ($callback, $output, $variables) {
return view('test.button');
});
@hook('hookName', true)
this content can be modified with dom parsers
you can inject some html here
@endhook