Laravel FCM Package
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM)., (*1)
It currently only supports HTTP protocol for :, (*2)
Note: The XMPP protocol is not currently supported., (*3)
To get the latest version of Laravel-FCM on your project, require it from "composer":, (*4)
$ composer require cimons/larafcm:dev-master
Or you can add it directly in your composer.json file:, (*5)
{ "require": { "cimons/larafcm": "dev-master" } }
Register the provider directly in your app configuration file config/app.php config/app.php
:, (*6)
'providers' => [ // ... Cimons\LaraFcm\LaraFcmServiceProvider::class, ]
Add the facade aliases in the same file:, (*7)
'aliases' => [ ... 'FCM' => Cimons\LaraFcm\Facades\FCM::class, ]
Copy the config file fcm.php
manually from the directory /vendor/cimons/larafcm/config
to the directory /config
(you may need to create this directory)., (*8)
In your .env
file, add the server key and the secret key for the Firebase Cloud Messaging:, (*9)
FCM_SERVER_KEY=my_secret_server_key FCM_SENDER_ID=my_secret_sender_id
A downstream message is a notification message, a data message, or both, that you send to a target device or to multiple target devices using its registration_Ids., (*10)
The following use statements are required for the examples below:, (*11)
use Cimons\LaraFcm\Message\NotificationBuilder; use Cimons\LaraFcm\Facades\FCM;
```php, (*12)
$notificationBuilder = NotificationBuilder('my title'); $notificationBuilder->setBody('Hello world') ->setSound('default'); $notification = $notificationBuilder->build();, (*13)
$token = "a_registration_from_your_database"; $downstreamResponse = FCM::sendTo($token, $notification);, (*14)
if ($downstreamResponse->isSent == 1) { echo "The message has been sent."; } else { echo "The message could not be sent." } ````, (*15)
This library is open-sourced software licensed under the MIT license., (*16)
Some of this documentation is coming from the official documentation. You can find it completely on the Firebase Cloud Messaging Website., (*17)