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

33 lines
884 B
PHP

<?php
namespace App\Notifications;
use App\Models\Notification as NotificationModel;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
class PushNotification extends Notification
{
public function __construct(
protected NotificationModel $notification
) {}
public function via($notifiable): array
{
return [WebPushChannel::class];
}
public function toWebPush($notifiable, $notification): WebPushMessage
{
return (new WebPushMessage)
->title($this->notification->title)
->body($this->notification->body)
->icon( '/img/app_icons/icon-192.png')
->data([
'url' => $this->notification->url,
'notification_id' => $this->notification->id,
]);
}
}