54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class ExchangeEventNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct(
|
|
public string $title,
|
|
public string $body,
|
|
public ?string $url = null,
|
|
public string $type = 'exchange_event',
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(object $notifiable): array
|
|
{
|
|
$preferences = $notifiable->notificationPreference()->firstOrCreate([]);
|
|
|
|
if (! $preferences->allows($this->type, 'database')) {
|
|
return [];
|
|
}
|
|
|
|
return ['database'];
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'type' => $this->type,
|
|
'title' => $this->title,
|
|
'body' => $this->body,
|
|
'url' => $this->url,
|
|
];
|
|
}
|
|
}
|