aliamassi / fcm-notification
Laravel package to send Firebase Cloud Messaging notifications to Android and iOS.
Requires
- php: >=8.0
- google/auth: ^1.20
- guzzlehttp/guzzle: ^7.0
This package is auto-updated.
Last update: 2025-07-09 09:18:53 UTC
README
Laravel package to send Firebase Cloud Messaging (FCM) notifications to Android and iOS devices.
Requirements
- PHP 8.0 or higher
- Laravel 8/9/10
- google/auth ^1.20
- guzzlehttp/guzzle ^7.0 fileciteturn1file3
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 fileciteturn1file5.
Publishing to Packagist
-
Tag your release:
git tag v1.0.0 git push --tags
-
Submit your repository on Packagist.
Contributing
Contributions are welcome! Please submit issues and pull requests.
License
MIT License. See the LICENSE file.