b4zz4r/laravel-firebase-notifications

This package is abandoned and no longer maintained. No replacement package was suggested.

Thin layer for integrate Firebase Messaging as Laravel Notifications

Installs: 7 763

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 2

pkg:composer/b4zz4r/laravel-firebase-notifications

This package has no released version yet, and little information is available.


README

Thin layer for integrate Firebase Messaging as Laravel Notifications

Requirement

  • PHP >= 7.1
  • Laravel >= 5.5 or 6.x

Installing

$ composer require "b4zz4r/laravel-firebase-notifications"

This is all, thanks to the Package Autodiscover.

Setup

Just place your Firebase credentials JSON to storage/firebase.credentials.json.

Advenced setup

Alternatively you can change file location using .env file.

FIREBASE_CREDENTIALS="/etc/firebase.credentials.json"

Or place JSON content directly to environment. It's cool for cloud services.

FIREBASE_CREDENTIALS="{\"type\": \"service_account\", ...}"

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.