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

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

paxha/laravel-fcm
=================

This package provides (Laravel Notification) channels for sending notifications via FCM (Firebase Cloud Messaging) using HTTP v1 API.

3.1(2y ago)102.2k↓49.2%4MITPHPPHP ^7.0|^8.0

Since Feb 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/paxha/laravel-fcm)[ Packagist](https://packagist.org/packages/paxha/laravel-fcm)[ RSS](/packages/paxha-laravel-fcm/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

Laravel FCM (Firebase Cloud Messaging) HTTP v1 API
==================================================

[](#laravel-fcm-firebase-cloud-messaging-http-v1-api)

[![Latest Stable Version](https://camo.githubusercontent.com/b7a1eff2f0d90b52d1584d9f63cbc8f502c40a418b9d375493d1fd077768823c/687474703a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d66636d2f76)](https://packagist.org/packages/paxha/laravel-fcm)[![Total Downloads](https://camo.githubusercontent.com/f5446c995609b5267e42a4c5faa28e462e08458999f15abebe614e26209aee40/687474703a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d66636d2f646f776e6c6f616473)](https://packagist.org/packages/paxha/laravel-fcm)[![Latest Unstable Version](https://camo.githubusercontent.com/70c615dd9d8bc25e1bac85e85df4aac41344ab5831907703def87e172dc5042b/687474703a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d66636d2f762f756e737461626c65)](https://packagist.org/packages/paxha/laravel-fcm)[![License](https://camo.githubusercontent.com/a362f2419e0832c125fabed609439bdf065b308b56374c843b3c7b0e185623ab/687474703a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d66636d2f6c6963656e7365)](https://packagist.org/packages/paxha/laravel-fcm)[![PHP Version Require](https://camo.githubusercontent.com/8f66fa76757f5333316fc7e44883bd3918e2b371f8c8a0bbd2c9b4ffda593d69/687474703a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d66636d2f726571756972652f706870)](https://packagist.org/packages/paxha/laravel-fcm)

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

[](#introduction)

This package provides ([Laravel Notification](https://laravel.com/docs/10.x/notifications)) **channels** for sending notifications via FCM (Firebase Cloud Messaging) using **HTTP v1 API**. For more information about the Firebase Cloud Messaging HTTP v1 API, please refer to the official documentation:

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

[](#installation)

To get started, you need to install the package via Composer:

```
composer require paxha/laravel-fcm
```

**Optional:** Once the package is installed, you can publish the configuration file using the following command:

```
php artisan vendor:publish --tag=fcm-config
```

This will create a new `fcm.php` file in your `config` directory, where you can configure your FCM settings. If you don't publish it, it will create a default channel named `fcm` with the default configuration.

Configuration
-------------

[](#configuration)

You can configure your FCM settings in the `fcm.php` file. Here's an example of the default configuration:

```
'fcm' => [ // this fcm key is the channel name you can create multiple channels over here...
    'project' => env('GOOGLE_PROJECT'),
    'service_account' => env('GOOGLE_SERVICE_ACCOUNT'),
],
```

You can also set your FCM settings in your `.env` file:

Please put your service account file at `config` folder and set the filename with path in the `.env` file.

You can create a service account file from the Google Cloud Console. For more information, please refer to the official:

```
GOOGLE_PROJECT=your-project-id
GOOGLE_SERVICE_ACCOUNT=firebase-certificates/service-account.json
```

Usage
-----

[](#usage)

To send a notification, you can use the channel provided by this package. Here's an example of how to send a notification using the `fcm` channel:

Before sending the notification, you need to use our `HasPushToken` trait in your notifiable model.

```
class YourModel extends Model
{
    use \LaravelFCM\Traits\HasPushToken;

    // if your model has a push token column name other than `push_token` then you can define it like this
    public function routeNotificationForFCM()
    {
        return $this->your_custom_column; // column name where you stored the push token
    }
}
```

Create a new notification using the following command:

```
php artisan make:notification NewMessage
```

```
