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.

72 lines
2.3 KiB

  1. <?php
  2. namespace App\Utilities\HelperClass;
  3. use App\Notifications\DBNotification;
  4. use App\Notifications\FcmNotification;
  5. use App\Notifications\MailNotification;
  6. use Illuminate\Support\Facades\Notification;
  7. class NotificationHelper
  8. {
  9. /**
  10. * Make notification object
  11. *
  12. * @param $payload
  13. * @param null $route
  14. * @param array $options
  15. * @return array
  16. */
  17. public function makeNotif($payload, $route = null, $options = []) {
  18. $route = $route == null ? "" : $route.'.';
  19. return [
  20. 'greeting' => $this->getMessageLine($payload, $route.'greeting'),
  21. 'subject' => $this->getMessageLine($payload, $route.'subject'),
  22. 'title' => $this->getMessageLine($payload, $route.'title'),
  23. 'body' => $this->getMessageLine($payload, $route.'body', $options)
  24. ];
  25. }
  26. /**
  27. * Fetch message from notifications lang file
  28. *
  29. * @param $payload
  30. * @param $key
  31. * @param null $options
  32. * @return array|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Translation\Translator|string|null
  33. *
  34. */
  35. public function getMessageLine($payload, $key, $options = [])
  36. {
  37. return __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.'.$key, $options);
  38. }
  39. /**
  40. * Call notifications
  41. *
  42. * @param $users
  43. * @param $notif
  44. */
  45. public function sendNotifications($users, $notif) {
  46. // switch ($level) {
  47. // case "emergency":
  48. //// Notification::send($users, new SmsNotification($notif));
  49. // case "critical":
  50. // Notification::send($users, new MailNotification($notif));
  51. // case "high":
  52. // Notification::send($users, new DBNotification($notif));
  53. // case "medium":
  54. // Notification::send($users, new FcmNotification($notif));
  55. // case "low":
  56. //// Notification::send($users, new SocketNotification($notif));
  57. // default:
  58. //// Notification::send($users, new SocketNotification($notif));
  59. // }
  60. Notification::send($users, new MailNotification($notif));
  61. Notification::send($users, new DBNotification($notif));
  62. Notification::send($users, new FcmNotification($notif));
  63. }
  64. }