PHPackages                             davidaldan/laravel-fcm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. davidaldan/laravel-fcm

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

davidaldan/laravel-fcm
======================

Laravel / Lumen package for Firebase Cloud Messaging

1.0.1(5y ago)06MITPHPPHP &gt;=5.5.9

Since Apr 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/davidaldan/Laravel-FCM)[ Packagist](https://packagist.org/packages/davidaldan/laravel-fcm)[ RSS](/packages/davidaldan-laravel-fcm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (4)Used By (0)

Laravel-FCM
===========

[](#laravel-fcm)

Introduction
------------

[](#introduction)

Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) (FCM).

It currently **only supports HTTP protocol** for :

- sending a downstream message to one or multiple devices
- managing groups and sending message to a group
- sending topics messages

Installation
------------

[](#installation)

Composer json file

```
$ "davidaldan/laravel-fcm": "0.0.*"

```

### Laravel

[](#laravel)

Register the provider directly in your app configuration file config/app.php `config/app.php`:

```
'providers' => [
	// ...

	LaravelFCM\FCMServiceProvider::class,
]
```

Add the facade aliases in the same file:

```
'aliases' => [
	...
	'FCM'      => LaravelFCM\Facades\FCM::class,
	'FCMGroup' => LaravelFCM\Facades\FCMGroup::class, // Optional
]
```

Publish the package config file using the following command:

```
$ php artisan vendor:publish --provider="LaravelFCM\FCMServiceProvider"

```

### Package Configuration

[](#package-configuration)

In your `.env` file, add the server key and the secret key for the Firebase Cloud Messaging:

```
FCM_SERVER_KEY=my_secret_server_key
FCM_SENDER_ID=my_secret_sender_id
```

### Downstream Messages

[](#downstream-messages)

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.

The following use statements are required for the examples below:

```
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
use LaravelFCM\Message\PayloadApnsBuilder;
use FCM;
```

#### Sending a Downstream Message to a Device

[](#sending-a-downstream-message-to-a-device)

```
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData([
	'a_data' 					=> 'my_data', //extra data can be array and with json_encode()
	'notification_foreground'	=> "true" //true-false
]);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

$token = "a_registration_from_your_database";

$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();

// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:error) - in production you should remove from your database the tokens
$downstreamResponse->tokensWithError();
```

#### Sending a Downstream Message to Multiple Devices

[](#sending-a-downstream-message-to-multiple-devices)

```
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);

$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
				    ->setSound('default');

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

// You must change it to get your tokens
$tokens = MYDATABASE::pluck('fcm_token')->toArray();

$downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();

// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:error) - in production you should remove from your database the tokens present in this array
$downstreamResponse->tokensWithError();
```

Notification Sound
------------------

[](#notification-sound)

Android:

```
->setChannelId('services_channel_id')

```

iOS:

```
$apnsBuilder = new PayloadApnsBuilder();
$apnsBuilder->addData([
	'payload' => [
		'aps' => [
			'sound'=>'default'
		]
	]
]);

```

Licence
-------

[](#licence)

This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

Some of this documentation is coming from the official documentation. You can find it completely on the [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) Website.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1853d ago

Major Versions

0.0.2 → 1.0.12021-04-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/33f89a9f8134a3ec580e5b497faab2521b37cdfc65f7109ef32390e73c9d2d0d?d=identicon)[davidaldan](/maintainers/davidaldan)

---

Top Contributors

[![davidaldan](https://avatars.githubusercontent.com/u/11914252?v=4)](https://github.com/davidaldan "davidaldan (6 commits)")

---

Tags

laravelpushlumennotificationfirebaseFCMFirebase Cloud Messaging

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davidaldan-laravel-fcm/health.svg)

```
[![Health](https://phpackages.com/badges/davidaldan-laravel-fcm/health.svg)](https://phpackages.com/packages/davidaldan-laravel-fcm)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
