1. Go to this page and download the library: Download bfg/web-hooker 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/ */
bfg / web-hooker example snippets
namespace App\Models;
use Bfg\WebHooker\Traits\WebHooked;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use WebHooked;
}
...
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(
public WebHook $hook,
public array $payload,
) {
//
}
...
namespace App\WebHook\Organizers;
use Bfg\WebHooker\Models\WebHook;
use Bfg\WebHooker\WebHookOrganizerInterface;
class YouOrganizer implements WebHookOrganizerInterface
{
/**
* Generate the event for hook emit
* @param WebHook $hook
* @return string
*/
function event(WebHook $hook): string
{
return YouEvent::class;
}
/**
* Method for remote subscribe
*
* To return the truth if the subscription was successful,
* otherwise there will be a repeated request for the next iteration.
*
* @param WebHook $hook
* @return bool
*/
public function subscribe(WebHook $hook): bool
{
// Request to subscribe
// Link for request: $hook->route_response
return true;
}
/**
* Method for remote unsubscribe
*
* To return the truth if the unsubscription was successful,
* otherwise there will be a repeated request for the next iteration.
*
* @param WebHook $hook
* @return bool
*/
public function unsubscribe(WebHook $hook): bool
{
// Request to unsubscribe
return true;
}
}