aliamassi/fcm-notification

Laravel package to send Firebase Cloud Messaging notifications to Android and iOS.

dev-main 2025-07-09 09:18 UTC

This package is auto-updated.

Last update: 2025-07-09 09:18:53 UTC


README

Packagist Version License Downloads

Laravel package to send Firebase Cloud Messaging (FCM) notifications to Android and iOS devices.

Requirements

Installation

composer require aliamassi/fcm-notification dev-main

If you want to publish the configuration file, run:

php artisan vendor:publish --provider="AliAmassi\FcmNotification\FirebaseNotificationServiceProvider" --tag="config"

Configuration

Copy your Firebase service account JSON to storage/app/firebase-service-account.json or set the path in your .env:

FIREBASE_CREDENTIALS=/full/path/to/firebase-service-account.json
FIREBASE_PROJECT_ID=your-firebase-project-id

The default config values are defined in config/fcm.php. After publishing, you can find the file at config/fcm.php.

Usage

Use the FirebaseNotification facade or inject AliAmassi\FcmNotification\FirebaseClient.

Sending a Single Notification

use FirebaseNotification;

$response = FirebaseNotification::send(
    'device-token',
    [
      'title' => 'Hello',
      'body' => 'This is a test notification',
    ],
    [
      'foo' => 'bar'
    ]
);

Sending to Multiple Devices

$tokens = ['token1', 'token2', 'token3'];

$response = FirebaseNotification::send(
    $tokens,
    ['title' => 'Batch Title', 'body' => 'Batch Body']
);

The client implementation handles obtaining and caching the access token via OAuth2 using your service account credentials fileciteturn1file5.

Publishing to Packagist

  1. Tag your release:

    git tag v1.0.0
    git push --tags
  2. Submit your repository on Packagist.

Contributing

Contributions are welcome! Please submit issues and pull requests.

License

MIT License. See the LICENSE file.