PHP code example of kz370 / laravel-firebase-notifications

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

    

kz370 / laravel-firebase-notifications example snippets


use FirebaseNotification;

$deviceToken = 'your-device-token-here';

FirebaseNotification::sendNotification(
    $deviceToken,
    'Hello there!',
    'Welcome to our platform 🎉',
    'https://example.com/welcome-banner.png',
    ['type' => 'welcome', 'user_id' => 123]
);

sendNotification(
    string $deviceToken,
    string $title,
    string $body,
    ?string $imageUrl = null,
    array $data = []
): array

FirebaseNotification::sendNotificationToTopic(
    'System Update',
    'We're upgrading our system tonight.',
    'https://example.com/update-banner.png',
    ['maintenance_mode' => true],
    'news'
);

sendNotificationToTopic(
    string $title,
    string $body,
    ?string $imageUrl = null,
    array $data = [],
    string $topic = 'all'
): array

use Kz370\FirebaseNotifications\Jobs\FirebaseNotificationJob;

FirebaseNotificationJob::dispatch(
    $deviceToken,
    'Queued Message',
    'This notification is sent via the queue!'
);

FirebaseNotificationJob::dispatch(
    null,
    'Breaking News',
    'Something big just happened!',
    null,
    ['category' => 'news'],
    true // Indicates it's for a topic
);

FirebaseNotificationJob::dispatch(
    $deviceToken,
    'Reminder',
    'Your session starts soon.'
)->delay(now()->addMinutes(10));

return [
    'service_account_path' => env('FIREBASE_SERVICE_ACCOUNT', storage_path('app/firebase-service-account.json')),
    'project_id' => env('FIREBASE_PROJECT_ID', 'your-project-id'),
];
bash
php artisan vendor:publish --provider="Kz370\FirebaseNotifications\FirebaseNotificationServiceProvider" --tag=config
bash
php artisan queue:work
bash
php artisan queue:work