Guest User

Untitled

a guest
Aug 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. 'fcm' => [
  2. 'priority' => 'normal',
  3. 'dry_run' => false,
  4. 'apiKey' => 'My-Api-key',
  5. ],
  6.  
  7. if(count($fcmDeviceIds) > 0) {
  8. $this->sendFCM($fcmDeviceIds, $payload, $addedPost);
  9. }
  10.  
  11. private function sendFCM($tokens, $payload, $addedPost) {
  12.  
  13. $poroductDetail = Product::find($addedPost->product_id)->first();
  14. $productTitle = $poroductDetail->title;
  15. $payloadData = ([$addedPost, 'notificationType' => 'postNotification']);
  16.  
  17. try {
  18. $push = new PushNotification('fcm');
  19. $feedback = $push->setMessage([
  20. 'fcm' => [
  21. 'alert' => [
  22. 'title' => isset($payload['title']) ? $payload['title'] : 'myTitle',
  23. 'body' => $payload['body']." for ".$productTitle
  24. ],
  25. 'sound' => isset($payload['sound']) ? $payload['sound'] : 'default'
  26.  
  27. ],
  28. 'extraPayLoad' => $payloadData
  29. ])->setDevicesToken($tokens)->send()->getFeedback();
  30.  
  31. } catch (Exception $ex) {
  32. Log::error($ex->getTraceAsString());
  33. }
  34. }
Add Comment
Please, Sign In to add comment