laravel-notification-channels / Fcm

Licence: mit
Firebase Cloud Messaging (FCM) notifications channel for Laravel

Projects that are alternatives of or similar to Fcm

Kotlin Firebase Group Chat
Group and OneonOne chat using firebase built in Kotlin similar to whatsapp.
Stars: ✭ 44 (-73.96%)
Mutual labels:  firebase, firebase-cloud-messaging, fcm
Pushraven
A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
Stars: ✭ 67 (-60.36%)
Mutual labels:  firebase, firebase-cloud-messaging, fcm
Laqul
A complete starter kit that allows you create amazing apps that look native thanks to the Quasar Framework. Powered by an API developed in Laravel Framework using the easy GraphQL queries language. And ready to use the Google Firebase features.
Stars: ✭ 110 (-34.91%)
Mutual labels:  firebase, laravel, firebase-cloud-messaging
Go Fcm
Firebase Cloud Messaging ( FCM ) Library using golang ( Go )
Stars: ✭ 212 (+25.44%)
Mutual labels:  firebase, firebase-cloud-messaging, fcm
Laravel Fcm
Firebase Cloud Messaging (FCM) sender for Laravel
Stars: ✭ 129 (-23.67%)
Mutual labels:  firebase, laravel, fcm
Laravel Firebase
A Laravel package for the Firebase PHP Admin SDK
Stars: ✭ 369 (+118.34%)
Mutual labels:  firebase, laravel, firebase-cloud-messaging
Fcm Toolbox
📲 Firebase Cloud Messaging toolbox
Stars: ✭ 217 (+28.4%)
Mutual labels:  firebase, firebase-cloud-messaging, fcm
Pyfcm
Python client for FCM - Firebase Cloud Messaging (Android, iOS and Web)
Stars: ✭ 674 (+298.82%)
Mutual labels:  firebase, firebase-cloud-messaging, fcm
Laravel Fcm
🌐 A Laravel package to send Push Notifications to one or many devices of the user.
Stars: ✭ 56 (-66.86%)
Mutual labels:  firebase, laravel
React Native Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 9,674 (+5624.26%)
Mutual labels:  firebase, fcm
Firebase Php
Unofficial Firebase Admin SDK for PHP
Stars: ✭ 1,657 (+880.47%)
Mutual labels:  firebase, firebase-cloud-messaging
Firebase Admin Node
Firebase Admin Node.js SDK
Stars: ✭ 1,050 (+521.3%)
Mutual labels:  firebase, firebase-cloud-messaging
Fcm
Enable Firebase Cloud Messaging for Capacitor apps
Stars: ✭ 120 (-28.99%)
Mutual labels:  firebase, fcm
Cocos2dx Cpp Sample
Firebase Cocos2d-x samples
Stars: ✭ 42 (-75.15%)
Mutual labels:  firebase, firebase-cloud-messaging
Hify
Social network powered by firebase
Stars: ✭ 115 (-31.95%)
Mutual labels:  firebase, firebase-cloud-messaging
Awesome Opensource Apps
🏠ℹ️ Curated list of awesome open source crafted web & mobile applications - Learn, Fork, Contribute & Most Importantly Enjoy!
Stars: ✭ 2,199 (+1201.18%)
Mutual labels:  firebase, laravel
Fcmsharp
Firebase Cloud Messaging (FCM) with .NET
Stars: ✭ 115 (-31.95%)
Mutual labels:  firebase, firebase-cloud-messaging
Push Receiver
A library to subscribe to GCM/FCM and receive notifications within a node process.
Stars: ✭ 125 (-26.04%)
Mutual labels:  firebase-cloud-messaging, fcm
Firebasecloudmessaging Android
FCM is just a demo of Android Application which implement Firebase Cloud Messaging. It made for Google I/O Extended 2016 Bangkok
Stars: ✭ 126 (-25.44%)
Mutual labels:  firebase, firebase-cloud-messaging
Rpush
The push notification service for Ruby.
Stars: ✭ 1,886 (+1015.98%)
Mutual labels:  firebase-cloud-messaging, fcm

Laravel FCM (Firebase Cloud Messaging) Notification Channel

Latest Version on Packagist Software License StyleCI Quality Score Total Downloads

This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) with Laravel 5.5+, 6.x, 7.x and 8.x.

Version 2 Released (March 4, 2020)

V2.0.0 has been released and FCM API calls has been migrated from legacy HTTP to HTTP v1 (docs from Firebase here). This is a breaking change so notifications using v1.x should not upgrade to v2.x of this package unless you plan on migrating your notification classes.

Contents

Installation

Install this package with Composer:

composer require laravel-notification-channels/fcm:~2.0

Setting up the FCM service

This package now uses the laravel-firebase library to authenticate and make the API calls to Firebase. Follow the configuration steps specified in their readme before using this.

After following their configuration steps, make sure that you've specified your FIREBASE_CREDENTIALS in your .env file.

Usage

After setting up your Firebase credentials, you can now send notifications via FCM by a Notification class and sending it via the FcmChannel::class. Here is an example:

use Illuminate\Notifications\Notification;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
use NotificationChannels\Fcm\Resources\AndroidConfig;
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
use NotificationChannels\Fcm\Resources\AndroidNotification;
use NotificationChannels\Fcm\Resources\ApnsConfig;
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;

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

    public function toFcm($notifiable)
    {
        return FcmMessage::create()
            ->setData(['data1' => 'value', 'data2' => 'value2'])
            ->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
                ->setTitle('Account Activated')
                ->setBody('Your account has been activated.')
                ->setImage('http://example.com/url-to-image-here.png'))
            ->setAndroid(
                AndroidConfig::create()
                    ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
                    ->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
            )->setApns(
                ApnsConfig::create()
                    ->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios')));
    }

    // optional method when using kreait/laravel-firebase:^3.0, this method can be omitted, defaults to the default project
    public function fcmProject($notifiable, $message)
    {
        // $message is what is returned by `toFcm`
        return 'app'; // name of the firebase project to use
    }
}

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|array
     */
    public function routeNotificationForFcm()
    {
        return $this->fcm_token;
    }
}

You can also return an array of tokens to send notifications via multicast to different user devices.

class User extends Authenticatable
{
    use Notifiable;

    ....

    /**
     * Specifies the user's FCM tokens
     *
     * @return string|array
     */
    public function routeNotificationForFcm()
    {
        return $this->getDeviceTokens();
    }
}

Once you have that in place, you can simply send a notification to the user by doing the following:

$user->notify(new AccountActivated);

Available Message methods

The FcmMessage class contains the following methods for defining the payload. All these methods correspond to the available payload defined in the FCM API documentation. Refer to this link to find all the available data you can set in your FCM notification.

setName(string $name)
setData(array $data)
setNotification(\NotificationChannels\Fcm\Resources\Notification $notification)
setAndroid(NotificationChannels\Fcm\Resources\AndroidConfig $androidConfig)
setApns(NotificationChannels\Fcm\Resources\ApnsConfig $apnsConfig)
setWebpush(NotificationChannels\Fcm\Resources\WebpushConfig $webpushConfig)
setFcmOptions(NotificationChannels\Fcm\Resources\FcmOptions $fcmOptions)
setTopic(string $topic)
setCondition(string $condition)

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

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

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].