trin4ik/laravel-expo-push
Composer 安装命令:
composer require trin4ik/laravel-expo-push
包简介
Laravel Expo Push Notification
README 文档
README
Simple and stupid package for send push notification with expo-notification service.
No tests, no mans, no routes/controllers for get tokens from clients etc. Only channel.
If u need more, use Alymosul/laravel-exponent-push-notifications
Installation
composer require trin4ik/laravel-expo-push
php artisan vendor:publish --provider "Trin4ik\LaravelExpoPush\ExpoPushServiceProvider"
U can log query to expo notification service into database with payloads and responses.
echo "EXPO_PUSH_LOG=true" >> .env php artisan migrate
Users expo tokens
U need add method routeNotificationForExpoPush any model, like User, who return expo token
<?php namespace App\Models; // ... class User extends Authenticatable { use Notifiable; // ... public function routeNotificationForExpoPush () { return $this->expo_token; // like ExponentPushToken[XXXXXXX_XXXXXXXXXXXXXX] } }
Change log database
By default, log write to expo_push_notification table, u can change it in 2 step:
- extends
Trin4ik\LaravelExpoPush\Models\ExpoPushNotification.phplike:
<?php namespace App\Models; class ExpoPushNotification extends Trin4ik\LaravelExpoPush\Models\ExpoPushNotification { protected $table = 'my_custom_notifications_table'; }
- change in
config/expo-push.phplog/driver/instanceto your new model:
return [ // ... 'log' => [ // ... 'driver' => [ // ... 'instance' => \App\Models\ExpoPushNotification::class ] ] ];
Usage
Like other channels, u need create Notification
php artisan make:notification PushTest
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel; use Trin4ik\LaravelExpoPush\ExpoPush; class PushTest extends Notification implements ShouldQueue { use Queueable; public function via($notifiable) { return [ExpoPushChannel::class]; } public function toExpoPush($notifiable) { return ExpoPush::create() ->badge(1) ->title("Congratulations!") ->body("Your " . $notifiable->email . " account was approved!"); } }
for more information about
ExpoPush::createmethods, look down
And usage like:
<?php use App\Notifications\PushTest; use App\Models\User; // ... $user = User::find(1); $user->notify(new PushTest);
ExpoPush::create methods
| Method | Type | Default | Platform | Description |
|---|---|---|---|---|
| data | array |
null |
iOS & Android | Any data to your app on click to push notification. Array converted to JSON, JSON may be up to about 4KiB |
| title | string |
null |
iOS & Android | Notification title |
| body | string |
null |
iOS & Android | Notification text |
| ttl | int |
Android: 2419200 iOS: 0 |
iOS & Android | TimeToLive, in seconds. Need to redelivery push |
| expiration | int |
null |
iOS & Android | Timestamp to expires message. Like ttl, but other format. ttl takes precedence over expiration |
| priority | enum(default, normal, high) |
default |
iOS & Android | Delivery priority |
| categoryId | string |
null |
iOS & Android | ID of the notification category that this notification is associated with. Find out more about notification categories here. Must be on at least SDK 41 or bare workflow |
| subtitle | string |
null |
iOS Only | Notification subtitle |
| sound | bool |
true |
iOS Only | Play sound when the recipient receives this notification |
| badge | int |
null |
iOS Only | Number to display in the badge on the app icon. Specify zero to clear the badge |
| mutableContent | bool |
null |
iOS Only | Specifies whether this notification can be intercepted by the client app. In Expo Go, this defaults to true, and if you change that to false, you may experience issues. In standalone and bare apps, this defaults to false |
| channelId | string |
null |
Android Only | ID of the Notification Channel through which to display this notification. If an ID is specified but the corresponding channel does not exist on the device (i.e. has not yet been created by your app), the notification will not be displayed to the user |
More info on Expo notification service message format
If new SDK release new format, u can create PR or use toArray() method in your Notification, like:
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel; class PushTest extends Notification implements ShouldQueue { use Queueable; public function via($notifiable) { return [ExpoPushChannel::class]; } public function toArray($notifiable) { return [ 'badge' => 1, 'title' => "Congratulations!", 'body' => "Your " . $notifiable->email . " account was approved!", 'new_expo_notification_param' => true ]; } }
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email trin4ik@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Thanks
❤️ This package was generated using the Laravel Package Boilerplate.
❤️ More code spizjeno from Alymosul/laravel-exponent-push-notifications
trin4ik/laravel-expo-push 适用场景与选型建议
trin4ik/laravel-expo-push 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.85k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「trin4ik」 「laravel-expo-push」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trin4ik/laravel-expo-push 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trin4ik/laravel-expo-push 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trin4ik/laravel-expo-push 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 1.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-27