semantechs / notification
用于处理所有类型通知的推送代理
Requires
- kreait/laravel-firebase: ^5.9
- pusher/pusher-php-server: ^7.2
README
打开 composer.json 并添加以下行
"autoload": {
....
"psr-4": {
....
"Sementechs\\Notification\\": "vendor/semantechs/notification/src/"
}
},
在配置文件夹中的 app.php 中添加以下行
'providers' => ServiceProvider::defaultProviders()->merge([
....
Sementechs\Notification\NotificationServiceProvider::class,
])->toArray(),
将您的 Firebase 服务账户文件放置在存储文件夹中,并在 .env 文件中添加文件名
FIREBASE_CREDENTIALS=file_name.json
BROADCAST_DRIVER=puhser
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
运行以下命令
composer dump-autoload
php artisan vendor:publish --tag=laravel-assets
php artisan migrate
可用方法
- 发送通知
$notificationObject = [ 'sender_id' => 1, 'receiver_ids' => [ 1, 2, 3 ], 'channel' => 'web', // web, mobile 'body' => [ 'title' => 'Title', 'body' => 'Detail' ], 'type' => 'admin' // admin, user ];
NotificationController::sendNotification($notificationObject);
- 获取所有通知
$type = web/user
NotificationController::getAllNotifications($type, $userId)
- 读取所有通知
$data = 所有通知的对象
NotificationController::readAll($data)