Skip to content

Commit 369f6eb

Browse files
committed
Fix Laravel notification payload generation
1 parent b6a55e7 commit 369f6eb

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/Channels/FcmV1Channel.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Edujugon\PushNotification\Channels;
44

5+
use Edujugon\PushNotification\Messages\PushMessage;
6+
57
class FcmV1Channel extends GcmChannel
68
{
79
/**
@@ -11,4 +13,59 @@ protected function pushServiceName()
1113
{
1214
return 'fcmv1';
1315
}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function buildData(PushMessage $message)
21+
{
22+
$data = [];
23+
24+
if ($message->title != null || $message->body != null) {
25+
$data = [
26+
'notification' => [
27+
'title' => $message->title,
28+
'body' => $message->body,
29+
],
30+
];
31+
}
32+
33+
if (
34+
$message->icon ||
35+
$message->color ||
36+
$message->sound ||
37+
$message->click_action ||
38+
$message->badge
39+
) {
40+
$data['android'] = [
41+
'notification' => []
42+
];
43+
44+
if (! empty($message->icon)) {
45+
$data['android']['notification']['icon'] = $message->icon;
46+
}
47+
48+
if (! empty($message->color)) {
49+
$data['android']['notification']['color'] = $message->color;
50+
}
51+
52+
if (! empty($message->sound)) {
53+
$data['android']['notification']['sound'] = $message->sound;
54+
}
55+
56+
if (! empty($message->click_action)) {
57+
$data['android']['notification']['click_action'] = $message->click_action;
58+
}
59+
60+
if (! empty($message->badge)) {
61+
$data['android']['notification']['notification_count'] = $message->badge;
62+
}
63+
}
64+
65+
if (! empty($message->extra)) {
66+
$data['data'] = $message->extra;
67+
}
68+
69+
return $data;
70+
}
1471
}

0 commit comments

Comments
 (0)