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/ */
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');