PHPackages                             katsana/fcm-notification - 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. katsana/fcm-notification

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

katsana/fcm-notification
========================

Firebase Cloud Messaging (FCM) Notification Channel for Laravel

v1.0.1(6y ago)53.4k1[2 issues](https://github.com/katsana/fcm-notification/issues)MITPHPPHP &gt;=7.2

Since Dec 16Pushed 5y ago4 watchersCompare

[ Source](https://github.com/katsana/fcm-notification)[ Packagist](https://packagist.org/packages/katsana/fcm-notification)[ Docs](https://github.com/katsana/fcm-notification)[ RSS](/packages/katsana-fcm-notification/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

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

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

This package makes it easy to send notifications using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) with Laravel 6.0+ using [kreait/laravel-firebase](https://github.com/kreait/laravel-firebase)

[![Build Status](https://camo.githubusercontent.com/c5fe4df44b637cf9b29a984b1b18e4df2acf800535627eeea5df28012df5d532/68747470733a2f2f7472617669732d63692e6f72672f6b617473616e612f66636d2d6e6f74696669636174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/katsana/fcm-notification)[![Latest Stable Version](https://camo.githubusercontent.com/0d57cc798f8e19d38ef1c9234ab1fbace6d2afd72f14889195659e6477ef45c4/68747470733a2f2f706f7365722e707567782e6f72672f6b617473616e612f66636d2d6e6f74696669636174696f6e2f762f737461626c65)](https://packagist.org/packages/katsana/fcm-notification)[![Total Downloads](https://camo.githubusercontent.com/4c85dc12ec93b8a8be1f528f14c9c165044d3592eccfc429952db6dc2eec7c48/68747470733a2f2f706f7365722e707567782e6f72672f6b617473616e612f66636d2d6e6f74696669636174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/katsana/fcm-notification)[![Latest Unstable Version](https://camo.githubusercontent.com/022e407141b3bc5d65e86faa8185448c7866b4fe4ee46df4b71fb613c129821c/68747470733a2f2f706f7365722e707567782e6f72672f6b617473616e612f66636d2d6e6f74696669636174696f6e2f762f756e737461626c65)](https://packagist.org/packages/katsana/fcm-notification)[![License](https://camo.githubusercontent.com/a4f801a9055128a40b55d7a608a525ec3b99f46b8952fe360d54ae0f350b0948/68747470733a2f2f706f7365722e707567782e6f72672f6b617473616e612f66636d2d6e6f74696669636174696f6e2f6c6963656e7365)](https://packagist.org/packages/katsana/fcm-notification)[![Coverage Status](https://camo.githubusercontent.com/72123c91184bad39a4cf43340594413fe9498802c949dc42135ce8909b009d9d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b617473616e612f66636d2d6e6f74696669636174696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/katsana/fcm-notification?branch=master)

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

[](#installation)

FCM Notification can be installed via composer:

```
composer require "katsana/fcm-notification"

```

### Configuration

[](#configuration)

> This part is based on [Firebase for Laravel Configuration](https://github.com/kreait/laravel-firebase#configuration)

In order to access a Firebase project and its related services using a server SDK, requests must be authenticated. For server-to-server communication this is done with a Service Account.

The package uses auto discovery to find the credentials needed for authenticating requests to the Firebase APIs by inspecting certain environment variables and looking into Google's well known path(s).

If you don't already have generated a Service Account, you can do so by following the instructions from the official documentation pages at [https://firebase.google.com/docs/admin/setup#initialize\_the\_sdk](https://firebase.google.com/docs/admin/setup#initialize_the_sdk).

Once you have downloaded the Service Account JSON file, you can use it to configure the package by specifying the environment variable `FIREBASE_CREDENTIALS` in your `.env` file:

```
FIREBASE_CREDENTIALS=/full/path/to/firebase_credentials.json
# or
FIREBASE_CREDENTIALS=relative/path/to/firebase_credentials.json

```

For further configuration, please see `config/firebase.php`. You can modify the configuration by copying it to your local config directory with the publish command:

```
php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config

```

Usages
------

[](#usages)

If a notification supports being sent as an FCM, you should define a `toFcm` method on the notification class. This method will receive a $notifiable entity and should return a `NotificationChannels\Fcm\Message` instance:

```
use NotificationChannels\Fcm\Message;

// ...

/**
 * Get the FCM representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \NotificationChannels\Fcm\Message
 */
public function toFcm($notifiable)
{
    return (new Message)
        ->notification('Your title', 'Your body');
}
```

### Routing FCM Notifications

[](#routing-fcm-notifications)

When sending notifications via the `fcm` channel, the notification system will automatically look for `routeNotificationForFcm` method on the entity:

```
