nimuli/app/Domains/Webhook/Services/WebhookDispatcher.php

21 lines
605 B
PHP

<?php
namespace App\Domains\Webhook\Services;
use App\Domains\Webhook\Jobs\DeliverWebhookJob;
use App\Domains\Webhook\Models\Webhook;
class WebhookDispatcher
{
public function dispatch(string $event, array $payload, int $workspaceId): void
{
Webhook::where('workspace_id', $workspaceId)
->where('is_active', true)
->whereJsonContains('events', $event)
->each(function (Webhook $webhook) use ($event, $payload) {
DeliverWebhookJob::dispatch($webhook, $event, $payload)
->onQueue('default');
});
}
}