Skip to content

Commit 68e0f00

Browse files
author
Riccardo
authored
add parameter to pass data array in the payload
https://firebase.google.com/docs/cloud-messaging/migrate-v1#node.js
1 parent f397061 commit 68e0f00

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/Notification.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,28 @@
1111

1212
class Notification extends Base {
1313

14-
public function setNotification($title, $message) {
14+
public function setNotification($title, $message, $data = null) {
1515
$this -> validateCurrent($title, $message);
16-
$this -> setPayload(
17-
array('notification' => array(
18-
'title' => $title,
19-
'body' => $message
20-
))
21-
);
16+
if (is_array($data) && count($data)>0){
17+
$this -> setPayload(
18+
array(
19+
'notification' =>
20+
array(
21+
'title' => $title,
22+
'body' => $message
23+
),
24+
'data' => $data
25+
)
26+
);
27+
28+
} else {
29+
$this -> setPayload(
30+
array('notification' => array(
31+
'title' => $title,
32+
'body' => $message
33+
))
34+
);
35+
}
2236
}
2337

2438
/**
@@ -28,4 +42,4 @@ public function setNotification($title, $message) {
2842
public function __invoke() {
2943
return parent ::__invoke();
3044
}
31-
}
45+
}

0 commit comments

Comments
 (0)