If you're looking for an easy way to send Firebase Cloud Messaging (FCM) push notifications in Laravel, I’ve developed a package called heyharpreetsingh/fcm that simplifies the process. It allows you to send notifications to mobile (Android, iOS) and web platforms efficiently.
How to Use: Install the package via Composer:
composer require heyharpreetsingh/fcm
Register the service provider in bootstrap/providers.php (Laravel 11) or config/app.php (Laravel 10 and below):
Heyharpreetsingh\FCM\Providers\FCMServiceProvider::class,
Set up Firebase credentials by generating a private key in Firebase Console and adding the path to the JSON file in your .env file:
FCM_GOOGLE_APPLICATION_CREDENTIALS=storage/ServiceAccount.json
Send a notification to individual devices like this:
use Heyharpreetsingh\FCM\Facades\FCMFacade;
FCMFacade::send([
"message" => [
"token" => "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", // Device token
"notification" => [
"body" => "This is an FCM notification message!",
"title" => "FCM Message"
]
]
]);
Was this guide helpful to you? Please support my work by leaving a 👏 clap as a token of appreciation.