
If you want to send push notifications from your Laravel application to mobile apps or the web, the simplest and fastest solution is to use Notifire.
The key advantage is that you can keep working within Laravel’s native Notifications system, without needing to reinvent the wheel, while seamlessly integrating with Firebase Cloud Messaging (FCM).
What is Notifire and Why Use It?
Notifire is a dedicated package for integrating Laravel with FCM.
It allows you to send notifications with either simple or advanced content, including:
-
Title
-
Body
-
Image
-
Icon
-
Sound
-
Actions
It also provides token management for different devices, making it easier to register and store them in your database.
Prerequisites
Before getting started, make sure you have:
-
A Firebase project already set up.
-
A Service Account JSON file, stored securely (e.g.,
storage/firebase.json
). -
Laravel Sanctum installed and configured, since token registration relies on it.
Installation
Notifire can be installed with just three commands:
Token Management
Notifire provides a Trait that you can add to your User model to manage FCM tokens.
-
Each notification must be sent to a specific device token.
-
If a user can log in from multiple devices, it’s best practice to create a dedicated devices table.
Registering Tokens from the Frontend
Notifire gives you a ready-made endpoint:
This endpoint is protected by Sanctum.
Each device (web or mobile) generates a token via Firebase, then sends it to your server to be stored and linked with the authenticated user.
Sending Notifications
You can send notifications in two ways:
-
Using the Notifire Facade directly.
-
Using Laravel’s built-in Notifications system.
Example with the Facade:
Best Practices
-
Always send notifications via queues to avoid slowing down your app.
-
Store Firebase credentials securely outside version control (e.g., not in Git).
-
Handle invalid or expired tokens, especially on logout.
-
Use Topics for broadcasting to large user segments.
Common Issues and Fixes
-
Notifications not delivered: Check Service Worker permissions (for web) or try re-registering the token.
-
401/403 errors on
/fcm/token
: Usually caused by Sanctum misconfiguration or missing token. -
Slow delivery: Use Workers to separate sending from the UI process.
Conclusion
Notifire makes integrating Laravel with FCM straightforward and reliable.
Once you set up token management, link them with your users, and offload sending to queues, you’ll have a powerful and scalable push notification system for both mobile and web applications.