irfanmumtaz / firebase-cloud-message

Laravel-FCM 是一个易于使用的包,与 Laravel 和 Firebase Cloud Messaging (FCM) 协作,用于发送推送通知。

安装次数: 2,200

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:项目

0.1.3 2024-01-22 18:55 UTC

This package is auto-updated.

Last update: 2024-09-23 08:22:56 UTC


README

Latest Stable Version Total Downloads License

LARAVEL FCM

Laravel-FCM 是一个易于使用的包,与 Laravel 和 Firebase Cloud Messaging (FCM) 协作,用于发送推送通知。

安装

使用 composer 安装 laravel fcm。

composer require irfanmumtaz/firebase-cloud-message

或者您可以直接在 composer.json 文件中添加它

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

Laravel

在您的应用程序配置文件 config/app.php 中直接注册提供者 config/app.php

'providers' => [
	// ...

	Irfanmumtaz\FirebaseCloudMessage\FCMServiceProvider::class,
]

使用以下命令发布包配置文件

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

用法

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
 */

贡献

欢迎拉取请求。对于重大更改,请先提出问题,以讨论您希望进行更改的内容。

许可

MIT