kemalnw/laravel-fcm
Composer 安装命令:
composer require kemalnw/laravel-fcm
包简介
A Laravel package to sent notification using Firebase Cloud Messsaging (FCM)
README 文档
README
A Laravel package to sent notification using Firebase Cloud Messsaging (FCM)
Installation
Require the kemalnw/laravel-fcm package in your composer.json and update your dependencies:
composer require kemalnw/laravel-fcm
Configuration
You must publish the config file to define your firebase server key :
php artisan vendor:publish --tag="fcm"
This is the content of the config file published at config/fcm.php
/** * Define your firebase server key */ return [ 'server_key' => env('FIREBASE_SERVER_KEY', ''), ];
Usage
Use artisan command to create a notification:
php artisan make:notification SomeNotification
Change the via method so that it becomes:
/** * Get the notification channels. * * @param mixed $notifiable * @return array|string */ public function via($notifiable) { return ['fcm']; }
Add method toFcm to your notification, and return an instance of Fcm Facade.
use Fcm; ... /** * Get the FCM representation of the notification. * * @param mixed $notifiable * @return void */ public function toFcm($notifiable) { return Fcm::notification([ 'title' => 'Hi!', 'body' => 'This is my first notification.' ]) ->timeToLive(604800); // 7 days in second }
When sending to specific device, the notification system will automatically look for a firebase_uid property on your notifiable entity. You may customize which firebase token is used to deliver the notification by defining a routeNotificationForFcm method on the entity:
... class User extends Authenticatable { use Notifiable; /** * Route notifications for the FCM channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForFcm($notification) { return $this->firebase_uid; } }
When sending to a topic, you may define so within the toFcm method in the notification:
use Fcm; ... /** * Get the FCM representation of the notification. * * @param mixed $notifiable * @return void */ public function toFcm($notifiable) { return Fcm::notification([ 'title' => 'Hi!', 'body' => 'This is my first notification.' ]) ->timeToLive(604800) // 7 days in second ->toTopic('topic-name'); }
kemalnw/laravel-fcm 适用场景与选型建议
kemalnw/laravel-fcm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 720 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kemalnw/laravel-fcm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kemalnw/laravel-fcm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 720
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-06