irfanmumtaz/firebase-cloud-message

Laravel-FCM is an easy to use package working with both Laravel for sending push notification with Firebase Cloud Messaging (FCM)

Installs: 2 843

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:project

0.1.3 2024-01-22 18:55 UTC

This package is auto-updated.

Last update: 2025-01-23 09:02:58 UTC


README

Latest Stable Version Total Downloads License

LARAVEL FCM

Laravel-FCM is an easy to use package working with both Laravel for sending push notification with Firebase Cloud Messaging (FCM)

Installation

Use composer to install laravel fcm.

composer require irfanmumtaz/firebase-cloud-message

Or you can add it directly in your composer.json file:

{
    "require": {
        "irfanmumtaz/firebase-cloud-message": "^0.1.1"
    }
}

Laravel

Register the provider directly in your app configuration file config/app.php config/app.php:

'providers' => [
	// ...

	Irfanmumtaz\FirebaseCloudMessage\FCMServiceProvider::class,
]

Publish the package config file using the following command:

$ php artisan vendor:publish --provider="Irfanmumtaz\FirebaseCloudMessage\FCMServiceProvider"

Usage

use Irfanmumtaz\FirebaseCloudMessage\FirebaseCM;
use Irfanmumtaz\FirebaseCloudMessage\NotificationBuilder;

//create notification builder
$notification = new NotificationBuilder("Test notification");
$notification->setBody("test")
        ->tag('larvael');

/**
 * you can set other notification params 
 * documentation here https://firebase.google.com/docs/cloud-messaging/http-server-ref
 * setBody(), setSound(), setBadge(), setClickAction(), setSubTitle(), setBodyLocKey(),
 * setBodyLocArgs(), setTitleLocKey(), setTitleLocArgs(), setAndroidChannelId(), setIcon(), setTag(),
 * setColor()
 */

//you can set option parameters
$notification->options->setCollapseKey("example")->setPriority("high");

/**
 * you can set other option params
 * documentation here https://firebase.google.com/docs/cloud-messaging/http-server-ref
 * setCollapseKey(), setPriority(), setContentAvailable(), setMutableContent(),
 * setTimeToLive(), setRestrictedPackageName(), setDryRun()
 * 
 */

//custom data can be added in this way
$notification->custom->addData("key1", "value1")->addData("key2", "value2");

/**
 * Other usable functions in custom data
 * addData("key", "value") you can add custom data as many you want
 * removeData() remove all keys from custom data
 * unsetData("key1") remove a single key from custom data
 * getData() get complete custom data as array
 */


//create an object for FCM and pass notification while creating object
$fcm = new FirebaseCM($notification);
$fcm->setTo('firebase key')->send();
/**
 * Other FCM functions 
 * setTo("key") uses for sending notification to a single user, pass token as string
 * setRegistrations(["key1", "key2"]) uses for sending notification to multiple users pass array of string
 * send() uses to send notificaiton
 */

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT