PHP code example of mrgarest / laravel-firebase-sender

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

    

mrgarest / laravel-firebase-sender example snippets


$firebaseSender = new FirebaseSender('MY_SERVICE_ACCOUNT_NAME');

$firebaseSender->setDeviceToken('DEVICE_TOKEN');

$firebaseSender->setTopic('TOPIC_NAME')

$firebaseSender->setTopic(TopicCondition::make()
    ->topic('topicA')
    ->and()
    ->group(fn($group) => $group->topic('topicB')->or()->topic('topicC'))
);

$firebaseSender->setNotification(new NotificationPush(
    title: 'TITLE',
    body: 'BODY'
));

$firebaseSender->setAndroid(new AndroidPush(
    title: 'TITLE',
    body: 'BODY'
));

$firebaseSender->setApns(new ApnsPush(
    title: 'TITLE',
    body: 'BODY'
));

$firebaseSender->send();

$firebaseSender->sendJob(Carbon::now()->addHours(1));

$firebaseSender->setMessage([
    'token' => 'DEVICE_TOKEN',
    'notification' => [
        'title' => 'TITLE',
        'body' => 'BODY'
    ]
]);

$auth = $firebaseSender->getAuthToken();

[
  "access_token" => "access_token"
  "expires_in" => 3599
  "token_type" => "Bearer"
]

$firebaseSender->setLog(
    true,
    'language',
    'en'
);

$query->messageId(45543643);

$query->serviceAccount('MY_SERVICE_ACCOUNT_NAME');

$query->deviceToken('DEVICE_TOKEN');

$query->topic('TOPIC_NAME');

$query->matchTopic('TOPIC_NAME');

$query->matchTopic(
    'TOPIC_NAME',
    true
);

$query->payload1('language');

$query->createdBetween(
    Carbon::now(),
    Carbon::now()->subHours(1)
);

$query->sentBetween(
    Carbon::now(),
    Carbon::now()->subHours(1)
);

$query->scheduledBetween(
    Carbon::now(),
    Carbon::now()->subHours(1)
);

$query->failedBetween(
    Carbon::now(),
    Carbon::now()->subHours(1)
);

php artisan vendor:publish --tag=firebase-sender-config

php artisan vendor:publish --tag=firebase-sender-migrations

php artisan make:migration