Firebase Cloud Messaging (FCM) Notification Channel for Laravel

v1.0.1 2020-04-03 06:00 UTC

This package is auto-updated.

Last update: 2024-06-29 04:46:42 UTC


Firebase Cloud Messaging (FCM) Notification Channel for Laravel

This package makes it easy to send notifications using Firebase Cloud Messaging with Laravel 6.0+ using kreait/laravel-firebase

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status


FCM Notification can be installed via composer:

composer require "katsana/fcm-notification"


This part is based on Firebase for Laravel 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.

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:

# or

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


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

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


namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
    use Notifiable;

     * Route notifications for the FCM channel.
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
    public function routeNotificationForFcm($notification)
        return $this->deviceToken;