ridhopujiono/fcm-send-notification

这使您能够更容易地使用FCM发送通知。无论是发送给个人还是所有用户

dev-master 2022-09-12 05:32 UTC

This package is auto-updated.

Last update: 2024-09-12 10:17:25 UTC


README

composer require ridhopujiono/fcm-send-notification

使用前

您必须为用户模型插入一个新列

php artisan make:migration add_device_token_to_users

运行该命令后,打开迁移文件并按照以下方式进行编辑

Schema::table('users', function (Blueprint  $table) {
    $table->string('device_token')->nullable();
});

执行迁移

php artisan migrate

设置环境文件

  • 打开您的 .env 文件

  • 在底部添加新行并添加如下代码

    SERVER_KEY_FCM='从Firebase获取的您的服务器密钥'

注意

您必须自行填写设备令牌字段。某种方式。因为通常来说,检索设备令牌需要一个客户端语言(例如JavaScript)

用法

首先使用

use RidhoPujiono\FcmSendNotification;

向所有用户发送通知

FcmSendNotification::sendNotificationAll($title, $body, $urlClick);

向特定用户发送通知

FcmSendNotification::sendNotificationSingle($user_id, $title, $body);