Push Notifications are essential for mobile apps. In this post, we’ll cover how to send push notifications from Laravel 12 to Android and iOS devices using Firebase Cloud Messaging (FCM).
🔧 Prerequisites
- Laravel 12 Installed
- Firebase Project Created
- Server Key from Firebase
- Device Token (Android/iOS)
📡 Method 1: Send FCM Push Notification using cURL in Laravel
You can send notifications using raw cURL via Laravel's HTTP client or PHP cURL.
Step 1: Use Laravel HTTP Client
Step 2: Use PHP cURL (Manual)
📦 Method 2: Use Laravel FCM Package
Use a Laravel package to simplify sending notifications via FCM.
Step 1: Install Package
Step 2: Add Configuration
Publish and set your FCM keys:
Edit config/fcm.php
with your Firebase credentials.
Step 3: Send Notification
📱 Android & iOS Notes
- Android: Make sure the app is in foreground or background to receive notifications.
- iOS: Requires APNs setup and APNs Auth Key in Firebase. iOS only displays notifications if sent via
notification
payload.
✅ Conclusion
With Laravel 12, sending push notifications is very flexible. Whether you use cURL, Laravel's HTTP Client, or a package like brozot/laravel-fcm
, you can quickly integrate powerful mobile messaging for your Android and iOS apps.
📁 Full Demo: Create Notification Test File in Laravel 12
Here’s how you can set up a full Laravel test to send a push notification using FCM for Android or iOS.
🚀 Step 1: Firebase Setup
- Go to Firebase Console.
- Create a new project or open an existing one.
- Navigate to Project Settings > Cloud Messaging.
- Copy your Server Key.
- Add your Android/iOS app in the Firebase project (optional but recommended for device registration).
📦 Step 2: Create Laravel Route and Controller
Create a route to trigger notification manually.
🛣️ Add Route in routes/web.php
🧾 Create Controller File
📤 Controller Code (app/Http/Controllers/PushTestController.php
)
🖥️ Step 3: Serve Your Laravel App
Run your Laravel project using the built-in server:
Open your browser and visit:
http://127.0.0.1:8000/send-test-notification
You should see a JSON response from Firebase, and the push notification should arrive on your Android or iOS device.
💡 Final Tips
- Make sure your device token is fresh (from Firebase SDK on Android/iOS).
- You can store and manage multiple tokens in a database for sending bulk notifications.
- Use Laravel queues for sending notifications asynchronously in production.
🔥 Laravel FCM Push Notifications with Database (Full Setup Demo)
This guide helps you set up Firebase Cloud Messaging (FCM) in Laravel using the laravel-notification-channels/fcm
package, store notifications in the database, and test on Android/iOS.
🧱 Step 1: Install Required Packages
🔐 Step 2: Firebase Credentials Setup
📢 Step 3: Create Notification Class
👤 Step 4: Add FCM Token to User Model
🧪 Step 5: Send a Test Notification
🧾 Step 6: View Stored Notifications
📚 Reference: Want to explore or suggest new FCM notification channels for Laravel?
Check out the official Laravel Notification Channels guide here:
Laravel Notification Channels – Suggest a New Channel
FAQs (with answers)
❓1. How do push notifications work in Laravel 12?
Laravel 12 uses external services like Firebase Cloud Messaging (FCM) to send push notifications. You store each user's device_token
and use Firebase to send messages.
❓2. What is Firebase Cloud Messaging (FCM)?
Firebase Cloud Messaging is a free service by Google that allows you to send real-time push notifications to Android, iOS, and web devices.
❓3. How do I save the device token in Laravel?
You create a new column (e.g. device_token
) in your users table, then use a controller or middleware to capture and store the token from the frontend.
❓4. Can I send push notifications to web browsers using Laravel?
Yes, Laravel can send web push notifications using Firebase with service workers and the browser’s Notification API.
❓5. Is Firebase free for push notifications?
Yes, Firebase offers a generous free tier for push notifications. You can send millions of notifications per month at no cost.
❓6. What packages do I need to send FCM notifications in Laravel?
You can use direct CURL requests or install packages like brozot/laravel-fcm
or laravel-notification-channels/fcm
for better integration.
❓7. How do I test push notifications locally?
You can test by registering a device in your browser or mobile app with Firebase and using Postman or your Laravel backend to send test messages.