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

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

rajtechnologies/laravel-fcm-notification
========================================

Google Firebase Cloud Messaging (FCM) Push Notification Channel for Laravel

026PHP

Since Sep 15Pushed 3y agoCompare

[ Source](https://github.com/RajTechnologiesPvtLtd/laravel-fcm-notification)[ Packagist](https://packagist.org/packages/rajtechnologies/laravel-fcm-notification)[ RSS](/packages/rajtechnologies-laravel-fcm-notification/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel FCM Notification
========================

[](#laravel-fcm-notification)

Laravel FCM (Firebase Cloud Messaging) Notification Channel

Use this package to send push notifications via Laravel to Firebase Cloud Messaging. Laravel 5.5+ required.

This package works only with [Legacy HTTP Server Protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref)

Install
-------

[](#install)

This package can be installed through Composer.

```
composer require rajtechnologies/laravel-fcm-notification
```

If installing on &lt; Laravel 5.5 then add the service provider:

```
// config/app.php
'providers' => [
    ...
    RajTechnologies\FCM\FcmNotificationServiceProvider::class,
    ...
];
```

Add your Firebase API Key in `config/services.php`.

```
return [

    ...
    ...
    /*
     * Add the Firebase API key
     */
    'fcm' => [
        'key' => env('FCM_SECRET_KEY')
     ]
];
```

Model of FCM

```
use RajTechnologies\FCM\Models\FCM;
```

Change in User Model

```
    public function fcm()
    {
        return $this->hasMany(FCM::class);
    }
```

Example Usage
-------------

[](#example-usage)

Use Artisan to create a notification:

```
php artisan make:notification SomeNotification
```

Return `[fcm]` in the `public function via($notifiable)` method of your notification:

```
public function via($notifiable)
{
    return ['fcm'];
}
```

Add the method `public function toFcm($notifiable)` to your notification, and return an instance of `FcmMessage`:

```
use RajTechnologies\FCM\FcmMessage;

...

public function toFcm($notifiable)
{
    $message = new FcmMessage();
    $message->content([
        'title'        => 'Foo',
        'body'         => 'Bar',
        'sound'        => '', // Optional
        'icon'         => '', // Optional
        'click_action' => '' // Optional
    ])->data([
        'param1' => 'baz' // Optional
    ])->priority(FcmMessage::PRIORITY_HIGH); // Optional - Default is 'normal'.

    return $message;
}
```

OR Add User Model Functions
===========================

[](#or-add-user-model-functions)

When sending to specific device using Modal, make sure your notifiable entity has `routeNotificationForFcm` method defined:

Add Method For Notification Function

```
public function routeNotificationForFcm($notification)
    {
        //For Single Token Only
        /*
        if($this->fcm){
            return $this->fcm[0]->token;
        }
        */
        if($this->fcm){
            $array = $this->fcm->pluck('token')->toArray();
        return implode(',',$array);
        }
        return null;
    }
```

Add Static Method For Update Token

```
public static function updateFCM($user_id,$fcm_token){
        $fcmQuery = FCM::query();
        $fcm = $fcmQuery->where('user_id',$user_id)->first();
        if($fcm){
            $fcm->update([
                "token" =>$fcm_token
            ]);
            return true;
        }
        $fcmQuery->create([
            "user_id" =>$user_id,
            "token" =>$fcm_token
        ]);
        return true;
    }
```

When sending to a topic, you may define so within the `toFcm` method in the notification:

```
use RajTechnologies\FCM\FcmMessage;

...

public function toFcm($notifiable)
{
    $message = new FcmMessage();
    $message->to('the-topic', $recipientIsTopic = true)
    ->content([...])
    ->data([...]);

    return $message;
}
```

Or when sending with a condition:

```
use RajTechnologies\FCM\FcmMessage;

...

public function toFcm($notifiable)
{
    $message = new FcmMessage();
    $message->contentAvailable(true)
        ->priority('high')
        ->condition("'user_".$notifiable->id."' in topics")
        ->data([...]);

    return $message;
}
```

You may provide optional headers or override the request headers using `setHeaders()`:

```
use RajTechnologies\FCM\FcmMessage;

...

public function toFcm($notifiable)
{
    $message = new FcmMessage();
    $message->setHeaders([
        'project_id'    =>  "123456789"   // FCM sender_id
    ])->content([
        'title'        => 'Foo',
        'body'         => 'Bar',
        'sound'        => '', // Optional
        'icon'         => '', // Optional
        'click_action' => '' // Optional
    ])->data([
        'param1' => 'baz' // Optional
    ])->priority(FcmMessage::PRIORITY_HIGH); // Optional - Default is 'normal'.

    return $message;
}
```

Interpreting a Response
-----------------------

[](#interpreting-a-response)

To process any laravel notification channel response check [Laravel Notification Events](https://laravel.com/docs/6.0/notifications#notification-events)

This channel return a json array response:

```
 {
    "multicast_id": "number",
    "success": "number",
    "failure": "number",
    "canonical_ids": "number",
    "results": "array"
 }
```

Check [FCM Legacy HTTP Server Protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream)for response interpreting documentation.

License
-------

[](#license)

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

First Inspiration of Admin Panel
--------------------------------

[](#first-inspiration-of-admin-panel)

- **[Laravel FCM (Firebase Cloud Messaging) Notification Channel (Ben Wilkins)](https://github.com/benwilkins/laravel-fcm-notification)**

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1921291?v=4)[rajtechnologies](/maintainers/rajtechnologies)[@rajtechnologies](https://github.com/rajtechnologies)

---

Top Contributors

[![bhargavraviya](https://avatars.githubusercontent.com/u/46953122?v=4)](https://github.com/bhargavraviya "bhargavraviya (13 commits)")

---

Tags

fcmfirebase-cloud-messaginglaravellaravel-applicationlaravel-firebase-push-notificationlaravel-packagenotifications

### Embed Badge

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

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

###  Alternatives

[maize-tech/laravel-email-domain-rule

Laravel Email Domain Rule

612.0k](/packages/maize-tech-laravel-email-domain-rule)[sarfraznawaz2005/noty

Laravel package to incorporate noty flash notifications into laravel.

324.5k](/packages/sarfraznawaz2005-noty)

PHPackages © 2026

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