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.

132 lines
2.2 KiB

  1. <?php
  2. namespace App\Channels\Messages;
  3. class FcmMessage
  4. {
  5. /**
  6. * The devices token to send the message from.
  7. *
  8. * @var array|string
  9. */
  10. public $to;
  11. /**
  12. * The topic of the FCM message.
  13. *
  14. * @var array
  15. */
  16. public $topic;
  17. /**
  18. * The data of the FCM message.
  19. *
  20. * @var array
  21. */
  22. public $data;
  23. /**
  24. * The notification body of the FCM message.
  25. *
  26. * @var array
  27. */
  28. public $notification;
  29. /**
  30. * The condition for receive the FCM message.
  31. *
  32. * @var array
  33. */
  34. public $condition;
  35. /**
  36. * The priority of the FCM message.
  37. *
  38. * @var string
  39. */
  40. public $priority = 'normal';
  41. /**
  42. * Set the devices token to send the message from.
  43. *
  44. * @param array|string $to
  45. * @return $this
  46. */
  47. public function to($to)
  48. {
  49. if (is_array($to) && count($to) === 1) {
  50. $this->to = $to[0];
  51. } else {
  52. $this->to = $to;
  53. }
  54. return $this;
  55. }
  56. /**
  57. * Set the topic of the FCM message.
  58. *
  59. * @param string $topic
  60. * @return $this
  61. */
  62. public function topic(string $topic)
  63. {
  64. $this->topic = $topic;
  65. return $this;
  66. }
  67. /**
  68. * Set the data of the FCM message.
  69. *
  70. * @param array $data
  71. * @return $this
  72. */
  73. public function data(array $data)
  74. {
  75. $this->data = $data;
  76. return $this;
  77. }
  78. /**
  79. * Set the notification of the FCM message.
  80. *
  81. * @param array $notification
  82. * @return $this
  83. */
  84. public function notification(array $notification)
  85. {
  86. $this->notification = $notification;
  87. return $this;
  88. }
  89. /**
  90. * Set the condition for receive the FCM message.
  91. *
  92. * @param string $condition
  93. * @return $this
  94. */
  95. public function condition(string $condition)
  96. {
  97. $this->condition = $condition;
  98. return $this;
  99. }
  100. /**
  101. * Set the priority of the FCM message.
  102. *
  103. * @param string $priority
  104. * @return $this
  105. */
  106. public function priority(string $priority)
  107. {
  108. $this->priority = $priority;
  109. return $this;
  110. }
  111. }