PHP code example of avto-dev / firebase-notifications-laravel

1. Go to this page and download the library: Download avto-dev/firebase-notifications-laravel 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/ */

    

avto-dev / firebase-notifications-laravel example snippets




return [

    // ...

    'providers' => [
        // ...
        AvtoDev\FirebaseNotificationsChannel\ServiceProvider::class,
    ],

];



return [

    // ...

    /*
    |--------------------------------------------------------------------------
    | Firebase Settings section
    |--------------------------------------------------------------------------
    |
    | Here you may specify some configs for FCM.
    |
    */

    'fcm' => [

        /*
         |----------------------------------------------------------------------
         | Firebase service driver
         |----------------------------------------------------------------------
         |
         | Value `file` or `config`:
         |   - Select `file` option to make service read json file
         |   - Select `config` option to set up all section in config file
         |
         */

        'driver' => env('FCM_DRIVER', 'config'),

        /*
         |---------------------------------------------------------------------
         | FCM Drivers
         |---------------------------------------------------------------------
         |
         | Here are each of the firebase.
         |
         */

        'drivers' => [

            'file' => [
                'path' => env('FCM_FILE_PATH', base_path('storage/fcm.json')),
            ],

            'config' => [

                 /*
                 |------------------------------------------------------------
                 | Credentials
                 |------------------------------------------------------------
                 |
                 | Content of `firebase.json` file in config. Using if
                 | `fcm.driver` is `config`. All fields 



use Illuminate\Notifications\Notification;
use AvtoDev\FirebaseNotificationsChannel\FcmChannel;
use AvtoDev\FirebaseNotificationsChannel\FcmMessage;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable, $notification)
    {
        return (new FcmMessage)
            ->setTitle('Approved!')
            ->setBody('Your account was approved!');
    }
}



use Illuminate\Notifications\Notifiable;
use AvtoDev\FirebaseNotificationsChannel\Receivers\FcmDeviceReceiver;
use AvtoDev\FirebaseNotificationsChannel\Receivers\FcmNotificationReceiverInterface;

class SomeNotifible
{
    use Notifiable;

    /**
    * Reveiver of firebase notification.
    *
    * @return FcmNotificationReceiverInterface
    */
    public function routeNotificationForFcm(): FcmNotificationReceiverInterface
    {
        return new FcmDeviceReceiver('firebase_token');
    }
}