alymosul / laravel-expo
为 Laravel 的 Exponent 推送通知驱动
v4.0.0
2023-05-12 18:24 UTC
Requires
- php: ^8.1
- alymosul/exponent-server-sdk-php: 1.3.*
- laravel/framework: ^10.0
Requires (Dev)
- mockery/mockery: ^1.5.0
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^9.5.10
README
内容
安装
您可以通过 composer 安装此包
composer require alymosul/laravel-exponent-push-notifications
如果您使用的是 Laravel 5.5 或更高版本,则此包将自动使用 包发现 注册自己。对于 Laravel 的旧版本,您必须手动安装服务提供者
// config/app.php 'providers' => [ ... NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider::class, ],
在发布 exponent 通知迁移之前,您必须在 .env 文件中添加
EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER=database
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="migrations"
发布迁移后,您可以通过运行迁移来创建 exponent_push_notification_interests
表
php artisan migrate
您可以选择使用以下命令发布配置文件
php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ 'interests' => [ /* * Supported: "file", "database" */ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ 'events' => [], 'table_name' => 'exponent_push_notification_interests', ], ] ];
用法
use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [ExpoChannel::class]; } public function toExpoPush($notifiable) { return ExpoMessage::create() ->badge(1) ->enableSound() ->title("Congratulations!") ->body("Your {$notifiable->service} account was approved!"); } }
可用消息方法
所有可用选项的列表
title('')
:接受一个字符串值作为标题。body('')
:接受一个字符串值作为正文。enableSound()
:启用通知声音。disableSound()
:静音通知声音。badge(1)
:接受一个整数值作为徽章。ttl(60)
:接受一个整数值作为存活时间。setJsonData('')
:接受一个 JSON 字符串或数组作为附加数据。channelID('')
:接受一个字符串以设置 Android 设备的通知的 channelId。priority('default')
:接受一个字符串以设置通知的优先级,必须是 [default, normal, high] 之一。
管理收件人
此包注册了两个处理收件人订阅的端点,这些端点在 src/Http/routes.php 文件中定义,由 ExpoController 使用,并通过包服务提供者加载。
路由消息
默认情况下,exponent "interest" 消息将被定义为 {notifiable}.{id} 约定,例如 App.User.1
,但是您可以通过在可通知类方法中包含一个 routeNotificationForExpoPushNotifications()
来更改此行为,该方法返回兴趣名称。
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 alymosul@gmail.com 而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。