1. Go to this page and download the library: Download diezeel/laravel-hooks 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/ */
$user = new User();
$user = Hook::get('fillUser',[$user],function($user){
return $user;
});
Hook::listen('fillUser', function ($callback, $output, $user) {
if (empty($output))
{
$output = $user;
}
$output->profilImage = ProfilImage::getForUser($user->id);
return $output;
}, 10);
$initialOutput='test string';
\Hook::get('testing',['other string'],function($otherString){
return $otherString;
},$initialOutput)
// and later ...
Hook::listen('testing', function ($callback, $output, $otherString) {
if ($output==='test string') {
$output="{$output} yeeeaaaayyy!";
}
if ($otherString==='other_string') {
// other string is good too
}
return $output; // 'test string yeeeaaaayyy!'
});
@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