PHP code example of eskater / laravel-fcm

1. Go to this page and download the library: Download eskater/laravel-fcm 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/ */

    

eskater / laravel-fcm example snippets


// config/app.php
'aliases' => [
    ...
    'Fcm' => Eskater\Fcm\FcmFacade::class,
];

return [

    /*
    * Your Fcm Server Key
    * Change to yours
    */

    'server_key' => '',

];

fcm()
    ->to($recipients) // $recipients must an array
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

fcm()
    ->toTopic($topic) // $topic must an string (topic name)
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

fcm()
    ->to($recipients) // $recipients must an array
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();

fcm()
    ->to($recipients) // $recipients must an array
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->useKey($serverKey) // $serverKey using another key
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->send();
 php
// config/app.php

'Providers' => [
    ...
    Eskater\Fcm\FcmServiceProvider::class,
]
 
bash
php artisan vendor:publish --provider="Eskater\Fcm\FcmServiceProvider"