Skip to content
/ fcm Public

📨 A PHP library to send push notification with Firebase Cloud Messaging

License

Notifications You must be signed in to change notification settings

ker0x/fcm

Repository files navigation

Fcm

A PHP libray to send push notification with Firebase Cloud Messaging

Warning

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

Installation

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');

Basic usage

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);

Documentation

The documentation is available here