davibennun / laravel-push-notification

Laravel package to enable sending push notifications to devices
1.23k stars 259 forks source link

FCM not working #195

Open mubassirhayat opened 6 years ago

mubassirhayat commented 6 years ago

Below is my code for FCM I tested it on an app a while and it worked like a charm but now for some reason, it's not working, can anyone of you help?

$androidDevices[] = PushNotification::Device($user->device_token);
$androidDevicesNotify = PushNotification::DeviceCollection($androidDevices);
$data = [
    'title' => "AppName",
    'body'  => 'You have a new request from User',
    'custom'  => [
        'request_id' => 1
    ]
];
$message = PushNotification::Message('You have a new request from User', $data);
$androidCollection = PushNotification::app('AppAndroid');
$androidCollection->adapter->setAdapterParameters(['sslverifypeer' => false]);
$androidCollection->to($androidDevicesNotify)->send($message);
Wolg commented 5 years ago

@mubassirhayat I know this is late, but if someone gets to the same problem – I got it working by updating zendframework/zendservice-google-gcm dependency: composer update davibennun/laravel-push-notification --with-dependencies Also make sure you message data contains notificationData key, so your message data could look as follows:

$data = [
    'title' => "AppName",
    'body'  => 'You have a new request from User',
    'notificationData'  => [
        'title' => 'AppName',
        'body' => 'You have a new request from User'
    ]
];