1. Go to this page and download the library: Download redjanym/fcm-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redjanym / fcm-bundle example snippets
use RedjanYm\FCM\Notification;
use RedjanYm\FCM\Recipient\Device;
// Using the notification factory (recommended)
$factory = $this->container->get('redjan_ym_fcm.notification_factory');
$notification = $factory->createDeviceNotification(
'device-token-here',
'Notification Title',
'Notification Body',
['key' => 'value'] // optional data payload
);
// Or manually
$notification = new Notification(
new Device('device-token-here'),
'Notification Title',
'Notification Body'
);
// Send
$client = $this->container->get('redjan_ym_fcm.client');
$response = $client->send($notification);
use RedjanYm\FCM\Notification;
use RedjanYm\FCM\Recipient\Topic;
// Using the notification factory (recommended)
$factory = $this->container->get('redjan_ym_fcm.notification_factory');
$notification = $factory->createTopicNotification(
'news',
'Breaking News',
'Something important happened',
['url' => 'https://example.com/article/123']
);
// Or manually
$notification = new Notification(
new Topic('news'),
'Breaking News',
'Something important happened'
);
// Send
$client = $this->container->get('redjan_ym_fcm.client');
$response = $client->send($notification);