Lae/app/Notifications/WebNotification.php

51 lines
1.0 KiB
PHP
Raw Normal View History

2023-01-11 12:19:05 +00:00
<?php
namespace App\Notifications;
2023-01-13 14:12:49 +00:00
use App\Notifications\Channels\WebChannel;
2023-01-11 12:19:05 +00:00
use Illuminate\Bus\Queueable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notification;
class WebNotification extends Notification
{
use Queueable;
public array|Model $message = [];
/**
* Create a new notification instance.
*
* @return void
*/
2023-01-13 14:26:13 +00:00
public function __construct(array|Model $message, string $event = 'notification')
2023-01-11 12:19:05 +00:00
{
if ($message instanceof Model) {
2023-01-13 14:26:13 +00:00
$this->message = $message->toArray();
} else {
$this->message = $message;
2023-01-11 12:19:05 +00:00
}
2023-01-13 14:26:13 +00:00
$this->message['event'] = $event;
2023-01-11 12:19:05 +00:00
}
/**
2023-01-11 12:20:24 +00:00
* Get the array representation of the notification.
2023-01-11 12:19:05 +00:00
*
* @return array
*/
2023-01-11 12:20:24 +00:00
public function toArray(): array
2023-01-11 12:19:05 +00:00
{
2023-01-11 12:20:24 +00:00
return $this->message;
2023-01-11 12:19:05 +00:00
}
/**
2023-01-11 12:20:24 +00:00
* Get the notification's delivery channels.
2023-01-11 12:19:05 +00:00
*
* @return array
*/
2023-01-11 12:20:24 +00:00
public function via(): array
2023-01-11 12:19:05 +00:00
{
2023-01-11 12:20:24 +00:00
return [WebChannel::class];
2023-01-11 12:19:05 +00:00
}
}