eskater/laravel-fcm

此包的最新版本(0.1.3)没有提供许可证信息。

一个用于在 Laravel 应用程序中发送 Firebase 通知的包

0.1.3 2018-10-18 03:30 UTC

This package is auto-updated.

Last update: 2024-09-10 08:13:45 UTC


README

原始库 - Kawankoding\Fcm

Laravel FCM

一个简单的包,可以帮助你在 Laravel 应用程序中发送 Firebase 通知

安装

您可以通过 composer 获取此包

$ composer require eskater/laravel-fcm

接下来,您必须注册服务提供者

// config/app.php

'Providers' => [
   ...
   Eskater\Fcm\FcmServiceProvider::class,
]

如果您想使用外观,也必须安装它

// config/app.php
'aliases' => [
    ...
    'Fcm' => Eskater\Fcm\FcmFacade::class,
];

接下来,您必须发布配置文件以定义您的 FCM 服务器密钥

php artisan vendor:publish --provider="Eskater\Fcm\FcmServiceProvider"

这是已发布文件的 内容

return [

    /*
    * Your Fcm Server Key
    * Change to yours
    */

    'server_key' => '',

];

使用方法

如果您只想使用通知参数发送 FCM,这是仅使用数据参数发送 FCM 的示例

fcm()
    ->to($recipients) // $recipients must an array
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

如果您想向主题发送 FCM,请使用方法 toTopic($topic) 而不是 to()

fcm()
    ->toTopic($topic) // $topic must an string (topic name)
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

如果您只想使用通知参数发送 FCM,这是仅使用通知参数发送 FCM 的示例

fcm()
    ->to($recipients) // $recipients must an array
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

如果您想同时使用数据和通知参数发送 FCM,这是同时使用数据和通知参数发送 FCM 的示例

fcm()
    ->to($recipients) // $recipients must an array
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->useKey($serverKey) // $serverKey using another key
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();