Files
FlightsAPI/app/Observers/NotificationObserver.php
T
2026-07-01 22:11:24 +10:00

24 lines
701 B
PHP

<?php
namespace App\Observers;
use App\Events\NotificationCreated;
use App\Models\Notification;
use App\Notifications\PushNotification;
class NotificationObserver
{
public function created(Notification $notification): void
{
\Log::info('Notification created: ' . $notification->id);
broadcast(new NotificationCreated($notification));
try {
$notification->user->notify(new \App\Notifications\PushNotification($notification));
\Log::info('WebPush notify() called for user ' . $notification->user_id);
} catch (\Throwable $e) {
\Log::error('WebPush send failed: ' . $e->getMessage(), ['exception' => $e]);
}
}
}