2017 © Pedro Peláez
 

library firebasecloudmessaging

This is to send push notification with firebase cloud messaging for Laravel. Tested in Laravel 5.2.*

image

saikatdutta1991/firebasecloudmessaging

This is to send push notification with firebase cloud messaging for Laravel. Tested in Laravel 5.2.*

  • Sunday, March 19, 2017
  • by saikatdutta1991
  • Repository
  • 2 Watchers
  • 1 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 17 % Grown

The README.md

Firebase Cloud Messaging

** Caveat: This package is not maintained anymore., (*1)

This Package is to enable sending push notifications to devices with firebase cloud messaging. Tested in Laravel 5.1 and 5.2, (*2)

#Installation

To install the package simply run this command in Laravel project root folder, (*3)

php composer.phar require saikatdutta1991/firebasecloudmessaging:1.0.0

add the service provider, (*4)


'providers' => [ /* * Laravel Framework Service Providers... */ ..... ..... \Saikat\FirebaseCloudMessaging\FCMServiceProvider::class ]

to config\app.php providers array, (*5)

Alias the PushManager class adding it to the aliases array in the config/app.php file., (*6)

    'aliases' => [
        ...
        'PushManager' => Saikat\FirebaseCloudMessaging\PushManager::class
    ]

But the alias is not mandatory., (*7)

Configuration

publish the package config to your laravel config folder with executing command, (*8)

php artisan vendor:publish --tag="config"

before executing this command add the service provider first, (*9)

add the fcm server_key in the config/firebase_cloud_messaging.php file, (*10)

    return [

        "server_key" => env('FIREBASE_CLOUD_MESSAGING_SERVER_KEY'),
        "fcm_push_url" => env("FIREBASE_CLOUD_MESSAING_URL")

    ];

fcm_push_url is not required already included in package. If want to override then add it, (*11)

# Usage

##including PushManager

If added in alias then use it in controller, (*12)

use PushManager;

IF not added in alias then use it in controller, (*13)

use Saikat\FirebaseCloudMessaging\PushManager;

##dependency injection in controller constructor

class YourController extends Controller
{

    public function __construct(PushManager $pushManager)
    {
        $this->pushManager = $pushManager;
    }

If want to use without injecting then, (*14)

class YourController extends Controller
{

    public function sendPushNotification()
    {
        $pushManager = app('PushManager'); // this will keep the PushManager instance singleton
    }

Example

<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller;
use PushManager;

class Controller extends Controller
{

    public function __construct(PushManager $pushManager)
    {
        $this->pushManager = $pushManager;
    }

    public function sendPushNotification()
    {
        $response = $this->pushManager
            ->setTitle('Test Title')
            ->setBody('Test Body')
            ->setIcon('icon url')
            ->setClickAction('https://www.google.com')
            ->setCustomPayload(['custom_data' => 'custom_data_array']) 
            ->setPriority(PushNotification::HIGH)
            ->setContentAvailable(true)
            ->setDeviceTokens('--------------------') // this can be an array or string
            ->push();

        dd( $response );
    }

}

To change response

->push(PushManager::STDCLASS)

PushManager::STDCLASS, PushManager::ARRY, PushManager::RAW, (*15)

by default response is PushManager::RAW set, (*16)

# Error Handle

$this->pushManager->getLastErrorCode() //if no error then 0

and, (*17)

$this->pushManager->getLastErrorMessage() // if no error then ""

# Future Enhancement

Now only raw response works proper. Json and stdClas response doesn't work for all types of fcm response. Returns null if failed to make json decode., (*18)

I will make the send push notification send asynchronous so that no wait for the response, (*19)

The Versions

19/03 2017

dev-master

9999999-dev

This is to send push notification with firebase cloud messaging for Laravel. Tested in Laravel 5.2.*

  Sources   Download

by Saikat Dutta

laravel composer gcm package firebase fcm push notification firebasecloudmessaging cloud messaging

19/03 2017

1.0.0

1.0.0.0

This is to send push notification with firebase cloud messaging for Laravel. Tested in Laravel 5.2.*

  Sources   Download

by Saikat Dutta

laravel composer gcm package firebase fcm push notification firebasecloudmessaging cloud messaging