-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Romain Monteil edited this page May 20, 2023
·
7 revisions
A PHP library to send push notification with Firebase Cloud Messaging
Version 3.x
of this library is a full rewrite using PSR-18 HTTP Client interface,
which means that no HTTP Client, like Guzzle or httplug,
are provided within. If you already have one in your project, the package will automatically discover it and use it.
Otherwise You will need to require one separately.
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\Notification\Notification;
use Kerox\Fcm\Model\Target;
$fcm = new Fcm('<oauth_token>', '<project_id>');
// Create the message
$message = new Message(
notification: new Notification(
title: 'Hello World',
body: 'My awesome Hello World!'
),
target: new Token('TopicA'),
data: [
'story_id' => 'story_12345',
],
)
// Send the message and get the response
$response = $fcm->send()->message($message);
The documentation is available here