I have a problem in my project. I am using edujugon push-notification for push notification of my app, I created push notification to android, ios devices successfully with title, body. But when I integrate the notification in my web devices it does not show the title and body rather it shows the site is upgrated in backend
. Also I want to set an url in my web notification. But dont know how.
Here is my code
public static function sendPushNotification($devices, $pushData, $partner = false) {
$android = $devices->where('type', 2)->pluck('token')->all();
if (!empty($android)) {
$push = new PushNotification('fcm');
$push->setMessage(
[
'data' => $pushData,
]
)
->setDevicesToken($android)
->send();
}
$ios = $devices->where('type', 1)->pluck('token')->all();
if (!empty($ios)) {
$push = new PushNotification('apn');
$feedback = $push->setMessage(
[
'aps' => [
'alert' => [
'title' => $pushData['title'],
'body' => $pushData['body'],
],
'sound' => 'default',
'badge' => 1
],
'data' => $pushData
]
)->setDevicesToken($ios)->send()->getFeedback();
}
$web = $devices->where('type', 3)->pluck('token')->all();
if (!empty($web)) {
$push = new PushNotification('fcm');
$push->setMessage($pushData)->setDevicesToken($web)->send();
}
}
and my push data is
$pushData = [
'title' => 'Test',
'body' => 'Test',
];
Please help me solving this
You should write this
if (!empty($web)) {
$push = new PushNotification('fcm');
$push->setMessage(
[
'notification' => $pushData,
]
)->setDevicesToken($web)->send();
}
Hopefully this will solve your problem.