PHPackages                             canerdogan/laravel-notification-channel-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. canerdogan/laravel-notification-channel-fcm

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

canerdogan/laravel-notification-channel-fcm
===========================================

FCM (Firebase Cloud Messaging) Notifications Driver for Laravel

1.5.1(6y ago)0149MITPHPPHP &gt;=5.6.4

Since Jun 27Pushed 6y agoCompare

[ Source](https://github.com/canerdogan/fcm)[ Packagist](https://packagist.org/packages/canerdogan/laravel-notification-channel-fcm)[ Docs](https://github.com/canerdogan/fcm)[ RSS](/packages/canerdogan-laravel-notification-channel-fcm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (5)Versions (13)Used By (0)

Laravel FCM (Firebase Cloud Messaging) Notification Channel
===========================================================

[](#laravel-fcm-firebase-cloud-messaging-notification-channel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9c0c62e8acd20b52e4275538957f144383a876ababbee67cd1ed69abb3afc530/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f726570726f632f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c2d66636d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coreproc/laravel-notification-channel-fcm)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/418be407dbc352d29ba3dd3d507853f3379a61623c56fb50ba6a1f4e82fe921a/68747470733a2f2f7374796c6563692e696f2f7265706f732f39313039383633302f736869656c64)](https://styleci.io/repos/91098630)[![SensioLabsInsight](https://camo.githubusercontent.com/930f1b5d9b13ba028c49ec9ba3fb0051a38623639b328c090d79ceb0433b1773/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f36323164373830662d666462372d343739642d386662322d3638336362626333656534632e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/621d780f-fdb7-479d-8fb2-683cbbc3ee4c)[![Quality Score](https://camo.githubusercontent.com/3078d721c90be0ba1d0581a969a3477438943856066cc4fb0d9b9d7ebc5b4c1b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f436f726550726f632f66636d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/CoreProc/fcm)[![Total Downloads](https://camo.githubusercontent.com/d787ad3ac93d81f5e545eb26b9039341c520e2d3c938a6ab4c2e9a67757b3d4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f726570726f632f6c61726176656c2d6e6f74696669636174696f6e2d6368616e6e656c2d66636d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coreproc/laravel-notification-channel-fcm)

This package makes it easy to send notifications using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) (FCM) with Laravel 5.3, 5.4, and 5.5.

Contents
--------

[](#contents)

- [Installation](#installation)
    - [Setting up the Fcm service](#setting-up-the-Fcm-service)
- [Usage](#usage)
    - [Available Message methods](#available-message-methods)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

Install this package with Composer:

```
composer require coreproc/laravel-notification-channel-fcm

```

Register the ServiceProvider in your config/app.php (Skip this step if you are using Laravel 5.5):

```
NotificationChannels\Fcm\FcmServiceProvider::class,

```

### Setting up the FCM service

[](#setting-up-the-fcm-service)

You need to register for a server key from Firebase for your application. Start by creating a project here:

Once you've registered and set up your prroject, add the API key to your configuration in `config/broadcasting.php`

```
'connections' => [
    ....
    'fcm' => [
        'key' => env('FCM_KEY'),
    ],
    ...
]

```

Usage
-----

[](#usage)

You can now send notifications via FCM by creating an `FcmNotification` and an `FcmMessages`:

```
class AccountActivated extends Notification
{
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable)
    {
        // The FcmNotification holds the notification parameters
        $fcmNotification = FcmNotification::create()
            ->setTitle('Your account has been activated')
            ->setBody('Thank you for activating your account.');

        // The FcmMessage contains other options for the notification
        return FcmMessage::create()
            ->setPriority(FcmMessage::PRIORITY_HIGH)
            ->setTimeToLive(86400)
            ->setFcmKey('xxxx') // (Optional) Use this to override the FCM key from broadcasting.php
            ->setNotification($fcmNotification);
    }
}
```

You will have to set a `routeNotificationForFcm()` method in your notifiable model. For example:

```
class User extends Authenticatable
{
    use Notifiable;

    ....

    /**
     * Specifies the user's FCM token
     *
     * @return string
     */
    public function routeNotificationForFcm()
    {
        return $this->fcm_token;
    }
}

```

Once you have that in place, you can simply send a notification to the user via

```
$user->notify(new AccountActivated);

```

### Available Message methods

[](#available-message-methods)

The `Message` object can differ between different operating systems (Android, iOS, and Chrome). In this perspective, a `Message` object is available for each platform which extends the `FcmMessage` object.

Mostly all the methods below are explained and defined in the Firebase Cloud Messaging documentation found here:

#### FcmMessage

[](#fcmmessage)

```
setFcmKey(string $fcmKey)
```

This method can be used to override the default FCM key defined in the `config/broadcasting.php` file.

```
setCondition(string $condition)
```

This parameter specifies a logical expression of conditions that determine the message target. Supported condition: Topic, formatted as "'yourTopic' in topics". This value is case-insensitive. Supported operators: &amp;&amp;, ||. Maximum two operators per topic message supported.

```
setCollapseKey(string $collapseKey)
```

This parameter identifies a group of messages (e.g., with collapse\_key: "Updates Available") that can be collapsed, so that only the last message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or becomes active.

Note that there is no guarantee of the order in which messages get sent.

Note: A maximum of 4 different collapse keys is allowed at any given time. This means a FCM connection server can simultaneously store 4 different send-to-sync messages per client app. If you exceed this number, there is no guarantee which 4 collapse keys the FCM connection server will keep.

```
setContentAvailable(bool $contentAvailable)
```

On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an inactive client app is awoken.

```
setMutableContent(bool $mutableContent)
```

Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNS payload. When a notification is sent and this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension.

```
setPriority(string $priority)
```

Sets the priority of the message. Valid values are `FcmMessage::PRIORITY_NORMAL` and `FcmMessage::PRIORITY::HIGH`. On iOS, these correspond to APNs priorities 5 and 10.

By default, notification messages are sent with high priority, and data messages are sent with normal priority. Normal priority optimizes the client app's battery consumption and should be used unless immediate delivery is required. For messages with normal priority, the app may receive the message with unspecified delay.

When a message is sent with high priority, it is sent immediately, and the app can wake a sleeping device and open a network connection to your server.

```
setTimeToLive($timeToLive)
```

This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks.

```
setDryRun(bool $dryRun)
```

This parameter, when set to `true`, allows developers to test a request without actually sending a message. Default value is `false`.

```
setData(string $data)
```

This parameter specifies the custom key-value pairs of the message's payload.

For example, with data:{"score":"3x1"}: On iOS, if the message is sent via APNS, it represents the custom data fields. If it is sent via FCM connection server, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse\_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string.

```
setNotification(FcmNotification $notification)
```

This parameter specifies the predefined, user-visible key-value pairs of the notification payload.

### Available Notification Methods

[](#available-notification-methods)

Each `FcmMessage` object expects an optional `notification` object which holds the content of the notification. A notification object for each platform is available which extends a main `FcmNotification` object.

#### FcmNotification

[](#fcmnotification)

```
setTitle(string $title)
```

The notification's title. This field is not visible on iOS phones and tablets.

```
setBody(string $body)
```

The notification's body text.

```
setClickAction(string $clickAction)
```

iOS: The action associated with a user click on the notification. Corresponds to category in the APNs payload.

Android: The action associated with a user click on the notification. If specified, an activity with a matching intent filter is launched when a user clicks on the notification.

Web: The action associated with a user click on the notification. For all URL values, secure HTTPS is required.

```
setAndroidChannelId(string $androidChannelId)
```

The notification's channel id (new in Android O).

The app must create a channel with this ID before any notification with this key is received.

If you don't send this key in the request, or if the channel id provided has not yet been created by your app, FCM uses the channel id specified in your app manifest.

```
setIcon(string $icon)
```

The notification's icon.

Android: Sets the notification icon to myicon for drawable resource myicon. If you don't send this key in the request, FCM displays the launcher icon specified in your app manifest.

Web: The URL to use for the notification's icon.

```
setBadge(string $badge)
```

This is an iOS specific variable. The value of the badge on the home screen app icon.

If not specified, the badge is not changed.

If set to 0, the badge is removed.

```
setSound(string $sound)
```

The sound to play when the device receives the notification.

Android: Supports "default" or the filename of a sound resource bundled in the app. Sound files must reside in `/res/raw/`.

iOS: Sound files can be in the main bundle of the client app or in the `Library/Sounds` folder of the app's data container.

```
setTag(string $tag)
```

Identifier used to replace existing notifications in the notification drawer.

If not specified, each request creates a new notification.

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.

```
setColor(string $color)
```

The notification's icon color, expressed in `#rrggbb` format.

```
setBodyLocKey(string $bodyLocKey)
```

The key to the body string in the app's string resources to use to localize the body text to the user's current localization.

```
setBodyLocArgs(array $bodyLocArgs)
```

The key to the title string in the app's string resources to use to localize the title text to the user's current localization.

```
setTitleLocKey(string $titleLocKey)
```

Variable string values to be used in place of the format specifiers in body\_loc\_key to use to localize the body text to the user's current localization.

```
setTitleLocArgs(array $titleLocArgs)
```

Variable string values to be used in place of the format specifiers in title\_loc\_key to use to localize the title text to the user's current localization.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Chris Bautista](https://github.com/chrisbjr)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 75.4% 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 ~96 days

Recently: every ~125 days

Total

10

Last Release

2370d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ee030ea353e879f8e20fdfb1ef38d9bb05e7f9dc862acdc44aa20e83182665c2?d=identicon)[canerdogan](/maintainers/canerdogan)

---

Top Contributors

[![chrisbjr](https://avatars.githubusercontent.com/u/571279?v=4)](https://github.com/chrisbjr "chrisbjr (43 commits)")[![MathieuMaas](https://avatars.githubusercontent.com/u/34303750?v=4)](https://github.com/MathieuMaas "MathieuMaas (2 commits)")[![awkwardusername](https://avatars.githubusercontent.com/u/2331465?v=4)](https://github.com/awkwardusername "awkwardusername (2 commits)")[![dwightwatson](https://avatars.githubusercontent.com/u/1100408?v=4)](https://github.com/dwightwatson "dwightwatson (1 commits)")[![edilbertloquine](https://avatars.githubusercontent.com/u/30011486?v=4)](https://github.com/edilbertloquine "edilbertloquine (1 commits)")[![erik-ropez](https://avatars.githubusercontent.com/u/1631035?v=4)](https://github.com/erik-ropez "erik-ropez (1 commits)")[![hklsk](https://avatars.githubusercontent.com/u/8273423?v=4)](https://github.com/hklsk "hklsk (1 commits)")[![jozefbalun](https://avatars.githubusercontent.com/u/8630488?v=4)](https://github.com/jozefbalun "jozefbalun (1 commits)")[![koenhoeijmakers](https://avatars.githubusercontent.com/u/2232776?v=4)](https://github.com/koenhoeijmakers "koenhoeijmakers (1 commits)")[![reinink](https://avatars.githubusercontent.com/u/882133?v=4)](https://github.com/reinink "reinink (1 commits)")[![shahvirag](https://avatars.githubusercontent.com/u/24240840?v=4)](https://github.com/shahvirag "shahvirag (1 commits)")[![canerdogan](https://avatars.githubusercontent.com/u/620056?v=4)](https://github.com/canerdogan "canerdogan (1 commits)")[![danieljaniga](https://avatars.githubusercontent.com/u/3395781?v=4)](https://github.com/danieljaniga "danieljaniga (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/canerdogan-laravel-notification-channel-fcm/health.svg)

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

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[laravel-notification-channels/fcm

FCM (Firebase Cloud Messaging) Notifications Driver for Laravel

5917.0M16](/packages/laravel-notification-channels-fcm)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[laravel-notification-channels/aws-sns

Amazon Simple Notification Service (AWS SNS) notification channel for Laravel.

541.1M2](/packages/laravel-notification-channels-aws-sns)

PHPackages © 2026

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