2017 © Pedro PelĆ”ez
 

library fcm-laravel-notification

Driver to connect laravel“s notification system to Google Firebase Cloud Messaging

image

douglasresendemaciel/fcm-laravel-notification

Driver to connect laravel“s notification system to Google Firebase Cloud Messaging

  • Tuesday, November 14, 2017
  • by douglasresendemaciel
  • Repository
  • 3 Watchers
  • 6 Stars
  • 576 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 1 Versions
  • 25 % Grown

The README.md

Firebase Cloud Messaging library for laravel“s notifications

This library allow send push notifications to Firebase Cloud Messaging through laravel“s notifications., (*1)

It“s possible send notifications to websites, Android and IOS without any other integration., (*2)

Installation

Run the following command from you terminal:, (*3)

bash composer require "douglasresendemaciel/fcm-laravel-notification:@dev", (*4)

or add this to require section in your composer.json file:, (*5)

"douglasresendemaciel/fcm-laravel-notification", (*6)

then run composer update, (*7)

Once it is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key., (*8)

'providers' => [
...
DouglasResende\FCM\NotificationServiceProvider::class
...

Usage

First, create your notification class using artisan php artisan make:notification MyNotification, (*9)

Implement your notification:, (*10)

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use DouglasResende\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, (*11)

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:, (*12)

...
'fcm' => [
    'key' => env('FCM_API_KEY','YOUR_API_KEY')
]
...

Trigger notification:, (*13)

$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, (*14)

The Versions

14/11 2017

dev-master

9999999-dev

Driver to connect laravel“s notification system to Google Firebase Cloud Messaging

  Sources   Download

MIT

The Requires

 

by Douglas Resende Maciel