besanek/laravel-firebase-notifications

There is no license information available for the latest version (v3.0.0) of this package.

Thin layer for integrate Firebase Messaging as Laravel Notifications

v3.0.0 2022-02-09 10:11 UTC

This package is auto-updated.

Last update: 2022-11-09 11:54:47 UTC


README

Thin layer for integrate Firebase Messaging as Laravel Notifications

Requirement

  • PHP = 8.x
  • Laravel = 9.x

Installing

$ 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.

    /**
     * It could be one device
     */
    public function routeNotificationForFirebase()
    {
        return $this->device_id;
    }
    
    /**
     * Or you can return array for multicast
     */
    public function routeNotificationForFirebase()
    {
        return $this->devices()->get()->pluck('id');
    }

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

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

And you can construct CloudMessage into toFirebase() method.

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

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