mtgofa/fcm-laravel-notification
Composer 安装命令:
composer require mtgofa/fcm-laravel-notification
包简介
Driver to connect laravel´s notification system to Google Firebase Cloud Messaging
README 文档
README
This library allow send push notifications to Firebase Cloud Messaging through laravel´s notifications.
It´s possible send notifications to websites, Android and IOS without any other integration.
Installation
Run the following command from you terminal:
composer require mtgofa/fcm-laravel-notification
or add this to require section in your composer.json file:
"mtgofa/fcm-laravel-notification"
then run composer update
Once it is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.
'providers' => [ ... MTGofa\FCM\NotificationServiceProvider::class ...
Usage
First, create your notification class using artisan php artisan make:notification MyNotification
Implement your notification:
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use MTGofa\FCM\Messages\FirebaseMessage; class MyNotification extends Notification { use Queueable; public function via($notifiable) { return ['fcm']; } public function toFcm($notifiable) { return (new FirebaseMessage())->setContent('Test Notification', 'This is a Test'); } }
Implement on your notifiable
use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; class User extends Model { use Notifiable; public function routeNotificationForFcm() { //return a device token, either from the model or from some other place. return $this->device_token; } }
Open up config/broadcasting.php and add the Firebase api key to the connections section:
... 'fcm' => [ 'key' => env('FCM_API_KEY','YOUR_API_KEY') ] ...
Trigger notification:
$User = User::find(1); //Send Notification $User->notify(new MyNotification());
References
For more information read the official documentation at https://laravel.com/docs/5.3/notifications
统计信息
- 总下载量: 247
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-17