warith/laravel-fcm-httpv1

A Laravel package to send Firebase Cloud Messaging (FCM) notifications across Laravel applications.

Maintainers

Package info

github.com/warith313/laravel-fcm-httpv1

pkg:composer/warith/laravel-fcm-httpv1

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2025-08-16 22:02 UTC

This package is auto-updated.

Last update: 2026-03-16 23:22:14 UTC


README

A simple package that helps you send Firebase notifications using HTTP v1 with your Laravel applications. ๐ŸŽฏ๐Ÿ“ฌ๐Ÿ’ก

Installation ๐Ÿ“ฆโšก๏ธ๐Ÿ’ป

You can install the package via composer: ๐ŸŽ‰๐Ÿ“ฅ๐Ÿ› ๏ธ

composer require warith313/laravel-fcm-httpv1 "^0.0.1"

Laravel Setup ๐Ÿ› ๏ธ๐Ÿ“ฃ๐Ÿš€

Register the service provider: ๐Ÿ—๏ธ๐Ÿ“ข๐Ÿ’ก

// config/app.php

'providers' => [
    // ...
    Warith\Fcm\FcmServiceProvider::class,
],

Optional: add the Facade for easy access: ๐Ÿช„๐Ÿ“˜โœจ

// config/app.php

'aliases' => [
    // ...
    'Fcm' => Warith\Fcm\FcmFacade::class,
],

Publish the config file: ๐Ÿ“‚๐Ÿ“ฃ๐Ÿ’ผ

php artisan vendor:publish --provider="Warith\Fcm\FcmServiceProvider"

Published file content (config/laravel-fcm.php): ๐Ÿ“๐Ÿ“Œ๐Ÿ”ง

return [

    /**
     * Path to your Firebase service account JSON file
     */
    'service_account_path' => env('FCM_SERVICE_ACCOUNT_PATH', storage_path('app/service-account.json')),

];

Set the path in your .env: ๐ŸŒŸ๐Ÿ“๐Ÿ“

FCM_SERVICE_ACCOUNT_PATH=/storage/app/service-account.json

Lumen Setup ๐Ÿ”ง๐Ÿ“กโšก๏ธ

Add the service provider in bootstrap/app.php: ๐Ÿ—๏ธ๐Ÿ’ก๐Ÿš€

$app->register(Warith\Fcm\FcmServiceProvider::class);

Copy the config file to config/laravel-fcm.php and configure before registering the provider: ๐Ÿ“โš™๏ธ๐Ÿ“‚

$app->configure('laravel-fcm');
$app->register(Warith\Fcm\FcmServiceProvider::class);

Methods Reference ๐Ÿ“œโš™๏ธ๐Ÿ“

  • ->to($recipients) โ€“ Send to a single token (string) or array of tokens
  • ->toTopic($topic) โ€“ Send to a topic
  • ->data($array) โ€“ Custom data payload
  • ->notification($array) โ€“ Notification payload
  • ->priority('high'|'normal') โ€“ Notification priority
  • ->timeToLive(seconds) โ€“ Time to live in seconds (0 to 2419200)
  • ->enableResponseLog() โ€“ Log raw Firebase response
  • ->send() โ€“ Send the message

Usage Examples ๐Ÿ“ฌ๐Ÿ”ฅ๐ŸŽฏ

1. Send only data payload: ๐Ÿ“Š๐Ÿ–‹๏ธโšก๏ธ

$recipients = [
    'token1...',
    'token2...',
];

fcm()
    ->to($recipients)
    ->priority('high')
    ->timeToLive(0)
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test FCM',
    ])
    ->send();

2. Send to a topic: ๐Ÿ“ข๐Ÿ“ฐ๐ŸŽฏ

$topic = 'news';

fcm()
    ->toTopic($topic)
    ->priority('normal')
    ->timeToLive(0)
    ->notification([
        'title' => 'Topic FCM',
        'body' => 'This is a topic test',
    ])
    ->send();

3. Send only notification payload: ๐Ÿ””๐Ÿ“โœจ

fcm()
    ->to($recipients)
    ->priority('high')
    ->timeToLive(0)
    ->notification([
        'title' => 'Test Notification',
        'body' => 'Notification only payload',
    ])
    ->send();

4. Send both data & notification payloads with image ๐Ÿ–ผ๏ธ๐Ÿ“ฑ๐ŸŒŸ

fcm()
    ->to($recipients)
    ->priority('high')
    ->timeToLive(0)
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a data payload',
        'type' => 'all',
        'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
        'image' => $image_link
    ])
    ->notification([
        'title' => 'Test FCM',
        'body' => 'This is a notification payload',
        'image' => $image_link
    ])
    ->send();

Note: When sending images, the package automatically sets mutable-content for APNs, adds image to Android notification, and includes Webpush headers. ๐Ÿ“ท๐Ÿ“ฒ๐ŸŽจ

Logging ๐Ÿ“๐Ÿ”๐Ÿ“‚

To see the raw Firebase response: ๐Ÿ–ฅ๏ธ๐Ÿ“‹โœจ

fcm()
    ->to($recipients)
    ->enableResponseLog()
    ->send();

Check logs at storage/logs/laravel.log. ๐Ÿ—‚๏ธ๐Ÿ“œ๐Ÿ”ฅ

Notes for HTTP v1 โšก๏ธ๐Ÿš€๐Ÿ’ก

  • token must be a single string per message. For multiple tokens, pass an array to ->to($tokens) and the package sends each individually.
  • APNs overrides (badge, mutable-content) are automatically added if image is provided.
  • Android overrides (click_action, image) are automatically handled.
  • Webpush image headers are automatically added if image is present.
  • timeToLive must be between 0 and 2419200 (28 days). ๐ŸŽฏ๐Ÿ“ฌ๐Ÿ“Œ

License ๐Ÿ”’

This package is open-sourced software licensed under the MIT license.