PHP code example of npav / laravel-fcm-push

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

    

npav / laravel-fcm-push example snippets


->withMiddleware(function (Middleware $middleware): void {
    $middleware->validateCsrfTokens(except: [
        'fcm-push/log',
    ]);
})

protected $except = [
    'fcm-push/log',
];

use Npav\FcmPush\Facades\FcmPush;

// Subscribe a device (typically called from your own controller, after your
// own validation that $channel refers to something real):
FcmPush::subscribe($channel, $fcmToken, $audience = null);

// Push to everyone subscribed to a channel:
FcmPush::sendToChannel(
    channel: $channel,
    title: 'New message',
    body: $commentText,
    data: ['tag' => "chat-{$ticketId}-{$commentId}", 'icon' => $iconUrl],
    url: $chatUrl,
);

// Push to only one audience within a channel (e.g. bidirectional chat —
// dealer messages notify 'admin' subscribers, admin messages notify
// everyone else):
FcmPush::sendToChannel($channel, $title, $body, data: [...], url: $url, audience: 'admin');
bash
php artisan vendor:publish --tag=fcm-push-assets