daldan26 / fcmv1
FCM HTTP V1 packages
v1.0.4
2024-08-28 14:56 UTC
Requires
- google/apiclient: ^2.12.1
- google/cloud-binary-authorization: ^0.5.0
README
A Laravel package that lets you use the new FCM Http V1 API and send push notifications with ease.
Firebase
- Go to the Firebase console.
Laravel
FCM_API_KEY="<firebase apiKey>" FCM_AUTH_DOMAIN="<firebase authDomain>" FCM_PROJECT_ID="<firebase projectId>" FCM_STORAGE_BUCKET="<firebase storageBucket>" FCM_MESSAGIN_SENDER_ID="<firebase messagingSenderId>" FCM_APP_ID="<firebase appId>" FCM_JSON="<name of the json file downloaded at firebase step 7 install>" FCM_API_SERVER_KEY=<api server key step 8-9 of firebase install>
- Package installation
composer require daldan26/fcmv1
- Register the provider in config/app.php
Daldan26\Fcmv1\FcmProvider::class,
- Publish config file
php artisan vendor:publish --tag=fcmv1 --ansi --force
Usage
Topics
Topics are used to make groups of device tokens. They will allow you to send notification directly to the topic where users are registered in.
Subscribe
To subscribe tokens to a topic :
use Daldan26\Fcmv1\FcmTopicHelper; $tokens = ["first token", ... , "last token"]; FcmTopicHelper::subscribeToTopic($tokens, "myTopic");
Unsubscribe
use Daldan26\Fcmv1\FcmTopicHelper; $tokens = ["first token", ... , "last token"]; FcmTopicHelper::unsubscribeToTopic($tokens, "myTopic");
List subscriptions
use Daldan26\Fcmv1\FcmTopicHelper; $token = "your awesome device token"; FcmTopicHelper::getTopicsByToken($token);
Notification
You can send notification to specific user or to topics.
Send to tokens
use Daldan26\Fcmv1\FcmNotification; $notify = new FcmNotification(); $notify->setTitle("Title")->setBody("Message here")->setToken(["token_here"])->setClickAction("NEWS")->send();
Send to topic
use Daldan26\Fcmv1\FcmNotification; $notify = new FcmNotification(); $notify->setTitle("Title")->setBody("Message here")->setTopic("general_topic")->setClickAction("NEWS")->send();