$data */ public function __construct( private WebhookConfiguration $webhookConfiguration, private string $eventName, private array $data ) {} public function handle(): void { $data = $this->data[0]; if ($this->webhookConfiguration->type === WebhookType::Discord) { $data = array_merge( is_array($data) ? $data : json_decode($data, true), ['event' => $this->webhookConfiguration->transformClassName($this->eventName)] ); $payload = json_encode($this->webhookConfiguration->payload); $tmp = $this->webhookConfiguration->replaceVars($data, $payload); $data = json_decode($tmp, true); $embeds = data_get($data, 'embeds'); if ($embeds) { foreach ($embeds as &$embed) { if (data_get($embed, 'has_timestamp')) { $embed['timestamp'] = Carbon::now(); unset($embed['has_timestamp']); } } $data['embeds'] = $embeds; } } try { $headers = []; if ($this->webhookConfiguration->type === WebhookType::Regular && $customHeaders = $this->webhookConfiguration->headers) { $headers = array_merge(['X-Webhook-Event', $this->eventName], $customHeaders); } Http::withHeaders($headers)->post($this->webhookConfiguration->endpoint, $data)->throw(); $successful = now(); } catch (Exception $exception) { report($exception->getMessage()); $successful = null; } $this->webhookConfiguration->webhooks()->create([ 'payload' => $data, 'successful_at' => $successful, 'event' => $this->eventName, 'endpoint' => $this->webhookConfiguration->endpoint, ]); } }