You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
<?php
|
|
|
|
|
|
namespace App\Channels;
|
|
|
|
use Illuminate\Notifications\Channels\DatabaseChannel;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class DBChannel extends DatabaseChannel
|
|
{
|
|
|
|
/**
|
|
* Get the data for the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @param \Illuminate\Notifications\Notification $notification
|
|
* @return array
|
|
*
|
|
* @throws \RuntimeException
|
|
*/
|
|
protected function getOptionalData($notifiable, Notification $notification)
|
|
{
|
|
if (method_exists($notification, 'toDatabaseOptional')) {
|
|
return is_array($data = $notification->toDatabaseOptional($notifiable))
|
|
? $data : [$data];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Build an array payload for the DatabaseNotification Model.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @param \Illuminate\Notifications\Notification $notification
|
|
* @return array
|
|
*/
|
|
protected function buildPayload($notifiable, Notification $notification)
|
|
{
|
|
return [
|
|
'id' => $notification->id,
|
|
'type' => get_class($notification),
|
|
'data' => $this->getData($notifiable, $notification),
|
|
'read_at' => null,
|
|
] + $this->getOptionalData($notifiable, $notification);
|
|
}
|
|
}
|