|
|
@ -0,0 +1,45 @@ |
|
|
|
<?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); |
|
|
|
} |
|
|
|
} |