Guest User

Untitled

a guest
Nov 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public static function sendPushNotification($devices, $pushData, $partner = false) {
  2.  
  3. $android = $devices->where('type', 2)->pluck('token')->all();
  4. if (!empty($android)) {
  5. $push = new PushNotification('fcm');
  6.  
  7. $push->setMessage(
  8. [
  9. 'data' => $pushData,
  10. ]
  11. )
  12. ->setDevicesToken($android)
  13. ->send();
  14. }
  15.  
  16. $ios = $devices->where('type', 1)->pluck('token')->all();
  17.  
  18. if (!empty($ios)) {
  19. $push = new PushNotification('apn');
  20.  
  21. $feedback = $push->setMessage(
  22. [
  23. 'aps' => [
  24. 'alert' => [
  25. 'title' => $pushData['title'],
  26. 'body' => $pushData['body'],
  27. ],
  28. 'sound' => 'default',
  29. 'badge' => 1
  30. ],
  31. 'data' => $pushData
  32. ]
  33. )->setDevicesToken($ios)->send()->getFeedback();
  34. }
  35.  
  36. $web = $devices->where('type', 3)->pluck('token')->all();
  37. if (!empty($web)) {
  38. $push = new PushNotification('fcm');
  39.  
  40. $push->setMessage($pushData)->setDevicesToken($web)->send();
  41. }
  42. }
Add Comment
Please, Sign In to add comment