PHP code example of saikatdutta1991 / firebasecloudmessaging

1. Go to this page and download the library: Download saikatdutta1991/firebasecloudmessaging library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

saikatdutta1991 / firebasecloudmessaging example snippets


php composer.phar 
 

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
            
        .....
        .....
        \Saikat\FirebaseCloudMessaging\FCMServiceProvider::class 
    ]

    'aliases' => [
        ...
        'PushManager' => Saikat\FirebaseCloudMessaging\PushManager::class
    ]
 
    return [
        
        "server_key" => env('FIREBASE_CLOUD_MESSAGING_SERVER_KEY'),
        "fcm_push_url" => env("FIREBASE_CLOUD_MESSAING_URL")

    ];


use PushManager;

use Saikat\FirebaseCloudMessaging\PushManager;

class YourController extends Controller
{
    
    public function __construct(PushManager $pushManager)
    {
        $this->pushManager = $pushManager;
    }

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



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 );
    }

}

->push(PushManager::STDCLASS)

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

$this->pushManager->getLastErrorMessage() // if no error then ""
json
php artisan vendor:publish --tag="config"