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