A PHP libray to send push notification with Firebase Cloud Messaging
Version 2.x
of this library is a full rewrite to be compliant with HTTP v1 API. If you are on Legacy HTTP API, then you should consider using version 1.x
You can install Fcm using Composer:
composer require kerox/fcm
You will then need to:
- run
composer install
to get these dependencies added to your vendor directory - add the autoloader to your application with this line:
require('vendor/autoload.php');
use Kerox\Fcm\Fcm;
use Kerox\Fcm\Model\Message;
use Kerox\Fcm\Model\Message\Notification;
$fcm = new Fcm('<oauth_token>', '<project_id>');
// Create a notification
$notification = new Notification('Hello World');
$notification->setBody('My awesome Hello World!');
// Create the message
$message = new Message($notification);
$message->setData([
'data-1' => 'Lorem ipsum',
'data-2' => '1234',
'data-3' => 'true'
]);
$message->setToken('1');
// Send the message and get the response
$response = $fcm->send()->message($message);
The documentation is available here