Notifire + FCM with Laravel
September 13, 2025If you want to send Push Notifications from your Laravel app to mobile or web clients, the fastest and simplest way is to use Notifire. It integrates Laravel directly with Firebase Cloud Messaging (FCM), so you can keep working inside Laravel’s native Notifications system without reinventing the wheel.
What is Notifire and why use it?
Notifire is a Laravel package built to connect with FCM. You can send notifications with simple or advanced payloads (title, body, image, icon, sound, actions…). It also helps you manage device tokens efficiently, making token registration and storage in your database much easier.
Requirements
Before starting, make sure you have: - An active Firebase Project. - The Service Account JSON file stored securely (e.g., storage/firebase.json). - Laravel Sanctum configured, since token registration endpoints are tied to it.
Installation Steps
Installation takes only 3 commands:
composer require devkandil/notifire
php artisan vendor:publish --provider="DevKandil\NotiFire\FcmServiceProvider"
php artisan migrate
Managing Tokens
The package provides a ready-to-use Trait you can add to your User model for FCM token management. This is essential since every notification needs to target a specific device token. For multi-device users, it’s better to create a dedicated devices table instead of storing a single token on the users table.
Registering Tokens from Frontend
Notifire provides a ready endpoint POST /fcm/token, which is protected by Sanctum. Any device (web or mobile) generates a token from Firebase and sends it to your backend to store and associate with the authenticated user.
Sending Notifications
You can either use the Facade directly or integrate with Laravel’s native Notification system. Both ways let you add title, body, image, extra data, and even set priority.
$ok = Fcm::withTitle('New Alert')
->withBody('There is an update on your account')
->sendNotification($token);
Best Practices
- Always send notifications through queues to avoid UI latency.
- Store Firebase credentials securely, never commit them to Git.
- Rotate invalid tokens or clear them after user logout.
- Use FCM Topics when you need to broadcast to large user segments.
Common Issues
- Notifications not delivered: check Service Worker setup on web or re-register the token.
- 401/403 on /fcm/token: usually Sanctum misconfiguration or missing token.
- Slow delivery: use Queue Workers and separate notification sending from the main request cycle.
Conclusion
Notifire makes Laravel + FCM integration straightforward and organized. Once you set up token management and use queues properly, you’ll have a reliable and scalable Push Notification system for both mobile and web applications.
Blog
Laravel 12.18.0 Update
Jun 17, 2025
Laravel 12.18.0 Update The Laravel team released version 12.18.0 with several cool updates: String encrypt() & decrypt() helpers are...
Explore the Most Powerful Modern Laravel Tools: Inertia.js, View Creators, and HLS — Step by Step
Jul 27, 2025
Here’s a complete breakdown of essential tools to level up your Laravel development: Inertia.js v2, View Creators, and the Laravel HLS package...
Mastering Modern CSS: The Power of if(), Popover Hints, and Smart Styling
Jul 16, 2025
🌐 Mastering Modern CSS: The Power of if(), Popover Hints, and Smart Styling CSS is getting smarter. In this guide, we’ll explore how the new...
Mastering Laravel Context: Advanced Logging and Contextual Job Tracing
Jul 20, 2025
Laravel Context is one of the most powerful new features in Laravel 12. It allows you to attach contextual data (like user ID, IP address, request pat...
Laravel 12.21.0 – A Smart Update for Cleaner Queries and Stricter Validation
Aug 03, 2025
Laravel 12.21.0 introduces two game-changing features aimed at writing cleaner, more maintainable code. The update includes the new whereValueBetwe...
Using Web Components the Smart Way
Jul 06, 2025
Using Web Components the Smart Way A lot of developers assume Web Components are meant to replace full SPA frameworks like React or Vue. But in rea...