Sending web push notifications from Laravel
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Sending Web Push Notifications from Laravel: The Developer's Guide
As a senior developer working with Laravel, you are focused on robust backend logic, efficient API design, and seamless user experiences. When you move from creating data (like a report) to notifying a user about that action, you step into the world of real-time communication and external services. The question—"Do I need Pusher or OneSignal?"—is crucial, as the answer depends entirely on whether you need simple event broadcasting or true, native device push delivery.
This post will walk you through the architecture required to send effective web push notifications from your Laravel application, focusing on practical solutions.
Understanding the Communication Gap
When a user creates a report in your Laravel backend, the server has the data but no direct way to initiate a push notification on their desktop operating system. Web push notifications are not something Laravel handles natively; they rely on browser APIs (Service Workers) and platform-specific permissions.
Therefore, you need an intermediary service to bridge the gap between your Laravel API response and the user's browser/device.
Pusher vs. Dedicated Push Services
The choice between services often comes down to what you are trying to achieve: real-time communication versus native push delivery.
1. Real-Time Broadcasting (Pusher/Laravel Echo)
Services like Pusher excel at broadcasting events in real-time across connected clients. If your goal is to update a dashboard immediately or trigger an action within the web application itself, Laravel’s built-in Broadcasting system using Pusher is an excellent choice. This handles data flow within the application context very well.
2. Native Push Notifications (OneSignal/FCM)
If you specifically want a notification that appears even when the user has the browser tab closed—a true desktop/mobile push notification—you need a dedicated service. Services like OneSignal or Firebase Cloud Messaging (FCM) are designed to manage the complex, platform-specific requirements of sending notifications directly to the operating system level. For external communication and high delivery rates, these specialized services are far superior for this task.
The Recommended Laravel Approach: Integrating a Push Service
For sending true web push notifications initiated by a backend event in Laravel, integrating a service like OneSignal is the most practical approach. This delegates the heavy lifting of operating system communication to experts.
Step-by-Step Implementation Flow
- Setup the Service: Sign up for a service (e.g., OneSignal) and integrate their SDK into your frontend application.
- Client Subscription: When a user first interacts with your site, they grant permission for notifications. The client then subscribes to receive future pushes.
- Laravel Event Trigger: After the report is successfully created in your Laravel controller, you trigger an event.
- Notification Dispatcher: You use that event to call the push service's API, sending the notification payload (title, body, data).
Conceptual Code Example (Laravel Side)
In your Laravel controller after successful report creation:
use App\Services\NotificationService; // Assume you create a service class
class ReportController extends Controller
{
protected $notificationService;
public function __construct(NotificationService $notificationService)
{
$this->notificationService = $notificationService;
}
public function createReport(Request $request)
{
// 1. Perform report creation logic...
$report = Report::create($request->all());
// 2. Trigger the notification service
$userId = auth()->id();
$recipientEmail = $report->user_email;
$this->notificationService->sendReportCreatedNotification(
$userId,
$recipientEmail,
'New Report Created!'
);
return response()->json(['message' => 'Report created successfully']);
}
}
The NotificationService would then handle the HTTP request to the external service (e.g., OneSignal API), passing the necessary data. This keeps your core business logic clean and leverages specialized tools for external delivery.
Conclusion
To summarize, if you need instantaneous updates within the web session, focus on Laravel Broadcasting with Pusher/WebSockets. However, if your requirement is to send a reliable, persistent push notification that reaches the user even when they are away from the browser, integrating a dedicated service like OneSignal is the correct architectural choice. Remember, as you build powerful applications using frameworks like Laravel, leveraging specialized services allows you to focus on building exceptional features rather than reinventing complex OS-level communication protocols. Utilizing external tools often leads to more stable and scalable solutions, which aligns perfectly with modern development practices advocated by platforms like Laravel Company.