PHP code example of viezel / webhooks
1. Go to this page and download the library: Download viezel/webhooks 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/ */
viezel / webhooks example snippets
Route::middleware('auth:api')->prefix('api')->as('webhooks.api.')->group(function() {
Route::get('hooks', Viezel\Webhooks\Controllers\API\ListWebhooks::class)->name('list');
Route::get('hooks/events', Viezel\Webhooks\Controllers\API\ListWebhookEvents::class)->name('events');
Route::post('hooks', Viezel\Webhooks\Controllers\API\CreateWebhook::class)->name('create');
Route::delete('hooks/{id}', Viezel\Webhooks\Controllers\API\DeleteWebhook::class)->name('delete');
});
use App\Models\Post;
use Viezel\Webhooks\Contracts\ShouldDeliverWebhooks;
class PostUpdatedEvent implements ShouldDeliverWebhooks
{
public function __construct(Post $post)
{
$this->post = $post;
}
public function getWebhookName(): string
{
return 'post:updated';
}
public function getWebhookPayload(): array
{
return [
'post' => $this->post->toArray(),
'extra' => [
'foo' => 'bar'
]
];
}
}
public function boot()
{
WebhookRegistry::listen(PostUpdatedEvent::class);
}
bash
php artisan vendor:publish --provider="Viezel\Webhooks\WebhooksServiceProvider" --tag="migrations"
php artisan migrate