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(): SendReport

$firebaseSender->sendJob(Carbon $scheduledAt, int $chunkLength = 10, int $maxRand = 0): void

$firebaseSender->clear(): void

$firebaseSender->setGroup(int $index): void

$firebaseSender = new FirebaseSender('MY_SERVICE_ACCOUNT_NAME');

$firebaseSender->setGroup(0);
$firebaseSender->setDeviceToken("MY_DEVICE_TOKEN_1");
$firebaseSender->setNotification(new NotificationPush(
    title: "Lorem ipsum",
    body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
));

$firebaseSender->setGroup(1);
$firebaseSender->setDeviceToken("MY_DEVICE_TOKEN_2");
$firebaseSender->setNotification(new NotificationPush(
    title: "Lorem ipsum",
    body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
));

$firebaseSender->send();

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

$firebaseSender->logEnabled(bool $enabled = true): void

$firebaseSender->setPayload1(?string $payload = null): void
$firebaseSender->setPayload2(?string $payload = null): void

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

use Garest\FirebaseSender\Facades\GoogleApi;
use Garest\FirebaseSender\Facades\ServiceAccount;

$account = ServiceAccount::getByName('MY_SERVICE_ACCOUNT_NAME');
$token = GoogleApi::getAccessToken($account);

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

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

php artisan make:migration