kutia-software-company/larafirebase
Composer 安装命令:
composer require kutia-software-company/larafirebase
包简介
Laravel Firebase Cloud Messaging.
README 文档
README
Introduction
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
Installation
Follow the steps below to install the package.
Composer
composer require kutia-software-company/larafirebase
Copy Config
Run php artisan vendor:publish --provider="Kutia\Larafirebase\Providers\LarafirebaseServiceProvider" to publish the larafirebase.php config file.
Get Athentication Key
Get Authentication Key from https://console.firebase.google.com/
Configure larafirebase.php as needed
'authentication_key' => '{AUTHENTICATION_KEY}'
Usage
Follow the steps below to find how to use the package.
Example usage in Controller/Service or any class:
use Kutia\Larafirebase\Facades\Larafirebase; class MyController { private $deviceTokens =['{TOKEN_1}', '{TOKEN_2}']; public function sendNotification() { return Larafirebase::withTitle('Test Title') ->withBody('Test body') ->withImage('https://firebase.google.com/images/social.png') ->withIcon('https://seeklogo.com/images/F/firebase-logo-402F407EE0-seeklogo.com.png') ->withSound('default') ->withClickAction('https://www.google.com') ->withPriority('high') ->withAdditionalData([ 'color' => '#rrggbb', 'badge' => 0, ]) ->sendNotification($this->deviceTokens); // Or return Larafirebase::fromArray(['title' => 'Test Title', 'body' => 'Test body'])->sendNotification($this->deviceTokens); } public function sendMessage() { return Larafirebase::withTitle('Test Title') ->withBody('Test body') ->sendMessage($this->deviceTokens); // Or return Larafirebase::fromArray(['title' => 'Test Title', 'body' => 'Test body'])->sendMessage($this->deviceTokens); } }
Example usage in Notification class:
use Illuminate\Notifications\Notification; use Kutia\Larafirebase\Messages\FirebaseMessage; class SendBirthdayReminder extends Notification { /** * Get the notification's delivery channels. */ public function via($notifiable) { return ['firebase']; } /** * Get the firebase representation of the notification. */ public function toFirebase($notifiable) { $deviceTokens = [ '{TOKEN_1}', '{TOKEN_2}' ]; return (new FirebaseMessage) ->withTitle('Hey, ', $notifiable->first_name) ->withBody('Happy Birthday!') ->asNotification($deviceTokens); // OR ->asMessage($deviceTokens); } }
Tips
- Check example how to receive messages or push notifications in a JavaScript client.
- You can use
larafirebase()helper instead of Facade.
Payload
Check how is formed payload to send to firebase:
Example 1:
Larafirebase::withTitle('Test Title')->withBody('Test body')->sendNotification('token1');
{
"registration_ids": [
"token1"
],
"notification": {
"title": "Test Title",
"body": "Test body"
},
"priority": "normal"
}
Example 2:
Larafirebase::withTitle('Test Title')->withBody('Test body')->sendMessage('token1');
{
"registration_ids": [
"token1"
],
"data": {
"title": "Test Title",
"body": "Test body"
}
}
If you want to create payload from scratch you can use method fromRaw, for example:
return Larafirebase::fromRaw([ 'registration_ids' => ['token1', 'token2'], 'data' => [ 'key_1' => 'Value 1', 'key_2' => 'Value 2' ], 'android' => [ 'ttl' => '1000s', 'priority' => 'normal', 'notification' => [ 'key_1' => 'Value 1', 'key_2' => 'Value 2' ], ], ])->send();
Made with ♥ by Gentrit Abazi (@gentritabazi).
kutia-software-company/larafirebase 适用场景与选型建议
kutia-software-company/larafirebase 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 678.99k 次下载、GitHub Stars 达 372, 最近一次更新时间为 2021 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kutia-software-company/larafirebase 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kutia-software-company/larafirebase 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 678.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 372
- 点击次数: 19
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-29
