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

  1. <?php
  2. namespace App\Channels;
  3. use Illuminate\Notifications\Channels\DatabaseChannel;
  4. use Illuminate\Notifications\Notification;
  5. class DBChannel extends DatabaseChannel
  6. {
  7. /**
  8. * Get the data for the notification.
  9. *
  10. * @param mixed $notifiable
  11. * @param \Illuminate\Notifications\Notification $notification
  12. * @return array
  13. *
  14. * @throws \RuntimeException
  15. */
  16. protected function getOptionalData($notifiable, Notification $notification)
  17. {
  18. if (method_exists($notification, 'toDatabaseOptional')) {
  19. return is_array($data = $notification->toDatabaseOptional($notifiable))
  20. ? $data : [$data];
  21. }
  22. }
  23. /**
  24. * Build an array payload for the DatabaseNotification Model.
  25. *
  26. * @param mixed $notifiable
  27. * @param \Illuminate\Notifications\Notification $notification
  28. * @return array
  29. */
  30. protected function buildPayload($notifiable, Notification $notification)
  31. {
  32. return [
  33. 'id' => $notification->id,
  34. 'type' => get_class($notification),
  35. 'data' => $this->getData($notifiable, $notification),
  36. 'read_at' => null,
  37. ] + $this->getOptionalData($notifiable, $notification);
  38. }
  39. }