dstpabuaran.com/app/Notifications/ErrorNotification.php

42 lines
1.0 KiB
PHP

<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
class ErrorNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public string $title,
public string $body,
public string $level = 'error',
public ?string $url = null,
) {}
/** @return list<class-string> */
public function via(object $notifiable): array
{
return [WebPushChannel::class];
}
public function toWebPush(object $notifiable, mixed $notification): WebPushMessage
{
$webPushMessage = (new WebPushMessage)
->title($this->title)
->icon('/icon-192x192.png')
->body($this->body);
if ($this->url) {
$webPushMessage->action('Lihat Detail', $this->url);
}
return $webPushMessage;
}
}