Download the PHP package amdadulhaq/fcm-laravel without Composer
On this page you can find all versions of the php package amdadulhaq/fcm-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amdadulhaq/fcm-laravel
More information about amdadulhaq/fcm-laravel
Files in amdadulhaq/fcm-laravel
Package fcm-laravel
Short Description A simple, lightweight, fast Firebase Cloud Messaging (FCM) notification channel for Laravel.
License MIT
Homepage https://github.com/amdad121/fcm-laravel
Informations about the package fcm-laravel
FCM (Firebase Cloud Messaging) for Laravel
A simple, lightweight, fast Firebase Cloud Messaging (FCM) notification channel for Laravel. No Firebase Admin SDK, no bloat — just push notifications, configurable, with a fake for testing.
Requirements
- PHP 8.2, 8.3, 8.4, or 8.5
- Laravel 12 or 13
Installation
The service provider is auto-discovered. Publish the config file:
Configuration
Set FIREBASE_CREDENTIALS to the path of your Firebase service account JSON file (download it from Project settings → Service accounts in the Firebase console). The Firebase project ID is read from that file automatically — nothing else is required to start sending.
See config/fcm.php for every option:
| Option | Env | Default | Purpose |
|---|---|---|---|
credentials |
FIREBASE_CREDENTIALS |
— | Path to the service account JSON. Absolute or relative to the app base path. |
http.timeout |
FCM_HTTP_TIMEOUT |
10 |
HTTP timeout (seconds) for the send request. |
http.retries |
FCM_HTTP_RETRIES |
2 |
Extra attempts after a 429, 5xx or connection error. 0 disables retries. |
http.retry_delay |
FCM_HTTP_RETRY_DELAY |
500 |
Delay (ms) before the first retry; doubles on each further attempt. A Retry-After header wins over it. |
http.max_retry_delay |
FCM_HTTP_MAX_RETRY_DELAY |
10000 |
Upper bound (ms) for any single retry delay, including Retry-After, so a queue worker is never parked for minutes. |
android.priority |
FCM_ANDROID_PRIORITY |
normal |
Default for every message's android payload. Set to null to omit. A notification can override it for itself alone — see Notifications. |
android.channel_id |
FCM_ANDROID_CHANNEL_ID |
default_channel |
Android notification channel ID. Set to null to omit. A notification can override it for itself alone too. |
apns.priority |
FCM_APNS_PRIORITY |
— | Sets apns.headers.apns-priority (5 or 10). Omitted from the payload unless set. |
debug |
FCM_DEBUG |
APP_DEBUG |
Logs skipped sends, rejected tokens, and delivery failures. Independent of the host app's app.debug. |
log_channel |
FCM_LOG_CHANNEL |
— | Log channel debug messages are written to. Defaults to the app's default channel. |
dry_run |
FCM_DRY_RUN |
false |
Builds and logs the message but never calls the FCM API; send() returns true as if it succeeded. Handy for local/staging. |
Notifications
Implement toFcm() on any notification, have it implement HasFcmPayload, and route it through the fcm channel:
FcmMessage is immutable: every with*() call returns a copy. The optional parts override the configured defaults for that one message only:
| Method | Effect |
|---|---|
withData(array $data) |
FCM data map (string values). |
withPriority('high'\|'normal') |
Overrides config('fcm.android.priority'). Anything else throws InvalidArgumentException. |
withChannelId(string $id) |
Overrides config('fcm.android.channel_id'). |
withBadge(int $count) |
App icon badge: apns.payload.aps.badge on iOS (0 clears it) and android.notification.notification_count on Android, where the launcher decides whether to show it. Negative counts throw. |
channel_id only changes which Android notification channel the OS delivers into — the app must still create that channel itself (flutter_local_notifications's createNotificationChannel, or NotificationManager.createNotificationChannel on native Android) with whatever importance/sound it wants; this package only stamps the outgoing message with the channel's ID.
The channel resolves device tokens via Laravel's standard routeNotificationFor('fcm', $notification) convention. Add a routeNotificationForFcm() method to the notifiable:
Sends to a token that FCM reports as unregistered or invalid throw internally and are reported through the AmdadulHaq\Fcm\Events\FcmTokenRejected event instead of stopping delivery to the notifiable's other tokens — listen for it to prune the dead token from wherever you store them. Only token errors count: UNREGISTERED, SENDER_ID_MISMATCH, and an INVALID_ARGUMENT that names message.token. An INVALID_ARGUMENT about the payload (for example a non-string data value) is logged as a failed send and the token is kept:
Sending directly
For a one-off send outside the notification system, use FcmService directly:
Testing
Use FcmService::fake() to swap the real service with an in-memory fake and assert on what would have been sent, without dispatching anything or hitting the network:
assertSent() / assertNotSent() callbacks receive (string $token, FcmMessage $message); assertSentTo()'s receives just the FcmMessage.
$fake->rejectToken($token) makes sends to that token throw FcmTokenRejectedException (without a real FCM error response), so you can exercise the FcmTokenRejected pruning path in tests.
Running the package's own test suite
License
MIT. See LICENSE.md.
All versions of fcm-laravel with dependencies
google/auth Version ^1.53
illuminate/notifications Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0