项目作者: besanek

项目描述 :
Thin layer for integrate Firebase Messaging as Laravel Notifications
高级语言: PHP
项目地址: git://github.com/besanek/laravel-firebase-notifications.git
创建时间: 2019-06-25T13:35:19Z
项目社区:https://github.com/besanek/laravel-firebase-notifications

开源协议:Other

下载


Laravel Firebase Notifications

Thin layer for integrate Firebase Messaging as Laravel Notifications

Requirement

  • PHP >= 8.1
  • Laravel = 10.x

Installing

  1. $ composer require "besanek/laravel-firebase-notifications"

This is all, thanks to the Package Autodiscover.

Setup

Please follow configuration guide of kreait/laravel-firebase

Basic Usage

Add new method routeNotificationForFirebase to your notifiable entity, witch returns device id.

  1. /**
  2. * It could be one device
  3. */
  4. public function routeNotificationForFirebase()
  5. {
  6. return $this->device_id;
  7. }
  8. /**
  9. * Or you can return array for multicast
  10. */
  11. public function routeNotificationForFirebase()
  12. {
  13. return $this->devices()->get()->pluck('id');
  14. }

In Notification entity you should add firebase to via() method.

  1. public function via(): array
  2. {
  3. return ['firebase', /* 'email', 'database', 'etc...'*/];
  4. }

And you can construct CloudMessage into toFirebase() method.

  1. public function toFirebase(): Messaging\CloudMessage
  2. $notification = Messaging\Notification::create('I <3 laravel', 'It is true');
  3. return Messaging\CloudMessage::new()->withNotification($notificatin);
  4. }

Please look into the official PHP SDK documentation for the full use of all possibilities.