kerox/fcm

A PHP library to send push notification through Firebase Cloud Messaging

2.3.0 2021-02-11 10:17 UTC

This package is auto-updated.

Last update: 2022-01-18 15:29:00 UTC


README

CI Coverage PHP Version Downloads Latest Stable Version License

Fcm

A PHP library 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