Download the PHP package devkandil/notifire without Composer
On this page you can find all versions of the php package devkandil/notifire. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devkandil/notifire
More information about devkandil/notifire
Files in devkandil/notifire
Package notifire
Short Description A Laravel package for sending Firebase Cloud Messaging (FCM) notifications
License MIT
Informations about the package notifire
Laravel FCM Notifier 🔥📬
Send push notifications with style, grace, and a tiny bit of panic.
A Laravel package for sending Firebase Cloud Messaging (FCM) notifications with support for Laravel's notification system.
Why?
Because your app deserves to annoy users in real-time — respectfully, of course.
Features
- Easy integration with Laravel's notification system
- Support for both simple and complex FCM messages
- Fluent interface for building notifications
- Automatic logging of notification delivery status
- Database migration for storing FCM tokens
- Configurable default settings
- Send notification to single or multiple topics
Coming Soon
- More methods
- Better docs
- A therapist for your app’s notification anxiety
Installation
You can install the package via composer:
Configuration
-
Publish the package files:
-
Add your Firebase project ID to your
.envfile: - Place your Firebase service account credentials JSON file in your Laravel storage directory:
Important: Make sure to add this file to your
.gitignoreto keep your credentials secure.
If you need to use a different location for your credentials file, you can modify the credentials_path value in the published config file (config/fcm.php).
-
Run the migrations:
- Add the
fcm_tokenfield to your model's$fillablearray:
This is required for the package to store FCM tokens.
Custom Model Configuration
By default, the package uses the User model and users table. To use a different model, update your config/fcm.php:
Note: Make sure to set the
tableconfig before running migrations, as the migration uses this value to determine which table to add thefcm_tokencolumn to.
Usage
Using the Facade
Direct Usage
Updating FCM Token
The package includes a built-in controller (FcmController) that handles FCM token updates. This controller is automatically loaded by the package and doesn't need to be published to your application.
You can use the provided API endpoint to update a user's FCM token:
Headers:
Request Body:
Response:
Note: The route is automatically registered with Sanctum authentication middleware. Make sure your user is authenticated with Sanctum before making this request.
Using the HasFcm Trait
Add the HasFcm trait to your model to easily manage FCM tokens and send notifications:
This trait provides the following methods:
Using Laravel Notifications
The package includes an example notification that demonstrates all available features:
To create your own notification:
-
Create a notification:
-
Implement the
toFcmmethod: -
Add the FCM channel to your notification:
-
Add the
HasFcmtrait to your Notifiable model (this automatically adds therouteNotificationForFcmmethod): - Send the notification:
Sending to Topics with Laravel Notifications
To send notifications to topics instead of individual users, use the toTopics() method on FcmMessage:
Or for multiple topics:
Then trigger the notification:
Raw FCM Messages
For complete control over the FCM message payload, you can use the fromRaw method. This method allows you to send a custom FCM message with your own payload structure:
This method is useful when you need to customize the FCM message beyond what the fluent interface provides, or when you're migrating from an existing FCM implementation.
Available Notification Options
The NotiFire package provides several options to customize your notifications:
| Option | Method | Description |
|---|---|---|
| Title | withTitle() |
Sets the notification title |
| Body | withBody() |
Sets the notification body text |
| Image | withImage() |
Sets an image URL to display in the notification |
| Icon | withIcon() |
Sets an icon to display with the notification |
| Color | withColor() |
Sets the color for the notification (in hexadecimal format, e.g., #FF5733) |
| Sound | withSound() |
Sets the sound to play when the notification is received |
| Click Action | withClickAction() |
Sets the action to perform when notification is clicked |
| Priority | withPriority() |
Sets the notification priority level |
| Additional Data | withAdditionalData() |
Sets additional data to send with the notification |
When using the HasFcm trait, you can pass these options as an array:
Logging
All notification attempts are automatically logged. You can find the logs in your Laravel log files with the following contexts:
- Successful notifications:
infolevel with message ID - Failed notifications:
errorlevel with error details - Missing FCM tokens:
warninglevel
You can disable logging by setting the FCM_LOGGING_ENABLED environment variable:
Debugging
By default, the package silently returns false when a notification fails to send. To help debug issues like cURL errors, authentication failures, or invalid tokens, you can enable exception throwing:
When enabled, the package will:
- Log the error (if logging is enabled)
- Throw the original exception instead of returning
false
This is useful for debugging production issues or during development when you want to see the exact error that occurred.
Testing
To run the tests, you need to have a valid Firebase configuration:
- Set up your Firebase project and obtain the credentials JSON file
-
Configure your
.envfile with the required Firebase variable: -
Place your Firebase service account credentials JSON file in your Laravel storage directory:
- Optionally, you can set a custom FCM test token in your
.envfile:
This is particularly useful when running tests in applications that use this package, as you won't be able to modify the test files in the vendor directory.
- When writing tests, make sure to use properly formatted FCM tokens. Firebase Cloud Messaging tokens follow a specific format:
The token typically consists of:
- A registration ID (before the colon)
- A colon separator
- A string starting with "APA91b" followed by a Base64-encoded payload
Using invalid token formats (like test-token) will cause tests to fail when run against the actual Firebase service.
Then run the tests:
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of notifire with dependencies
laravel/framework Version ^10.0|^11.0|^12.0|^13.0
google/apiclient Version ^2.0