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
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
.env
file: - Place your Firebase service account credentials JSON file in your Laravel storage directory:
Important: Make sure to add this file to your
.gitignore
to 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_token
field to your User model's$fillable
array:
This is required for the package to store FCM tokens in your user model.
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
toFcm
method: -
Add the FCM channel to your notification:
-
Add the
HasFcm
trait to your Notifiable model (this automatically adds therouteNotificationForFcm
method): - Send 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:
info
level with message ID - Failed notifications:
error
level with error details - Missing FCM tokens:
warning
level
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
.env
file 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
.env
file:
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.