2025-10-10 15:57:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Notifications\Channels;
|
|
|
|
|
|
2025-10-10 15:59:17 +00:00
|
|
|
use App\Jobs\SendWebhookJob;
|
2025-10-10 15:57:10 +00:00
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
|
|
class WebhookChannel
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Send the given notification.
|
|
|
|
|
*/
|
2025-10-10 16:08:37 +00:00
|
|
|
public function send($notifiable, Notification $notification): void
|
2025-10-10 15:57:10 +00:00
|
|
|
{
|
|
|
|
|
$webhookSettings = $notifiable->webhookNotificationSettings;
|
|
|
|
|
|
|
|
|
|
if (! $webhookSettings || ! $webhookSettings->isEnabled() || ! $webhookSettings->webhook_url) {
|
2025-10-10 16:07:04 +00:00
|
|
|
if (isDev()) {
|
|
|
|
|
ray('Webhook notification skipped - not enabled or no URL configured');
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 15:57:10 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 15:59:17 +00:00
|
|
|
$payload = $notification->toWebhook();
|
2025-10-10 15:57:10 +00:00
|
|
|
|
2025-10-10 16:07:04 +00:00
|
|
|
if (isDev()) {
|
|
|
|
|
ray('Dispatching webhook notification', [
|
|
|
|
|
'notification' => get_class($notification),
|
|
|
|
|
'url' => $webhookSettings->webhook_url,
|
|
|
|
|
'payload' => $payload,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 15:59:17 +00:00
|
|
|
SendWebhookJob::dispatch($payload, $webhookSettings->webhook_url);
|
2025-10-10 15:57:10 +00:00
|
|
|
}
|
|
|
|
|
}
|