Laravel Notification Center is a high-performance, enterprise-grade notification microservice built with Laravel 12 and PHP 8.4. It provides a scalable, multi-channel architecture for dispatching real-time notifications via Email, SMS, Push, Slack, and WhatsApp.
This project is architected for maximum portability and developer productivity. It operates in two distinct modes:
- Standalone Microservice (Plug & Play): The root repository is a lightweight, fully configured Laravel 12 implementation. It acts as an independent REST API service for orchestrating your system notifications, complete with Database configurations, API endpoints, and real-time Pulse monitoring.
- Domain Package Integration: The core engine lives completely encapsulated inside
packages/notification-center. You can install this specific directory into your existing Laravel monoliths as a local package, consuming the Notification Center as an internal Domain Driven package without running a separate server.
For detailed information on how to use the raw Domain logic, refer to the Internal Package README.
The Notification Center acts as a centralized brain for outbound application messaging. It abstracts away the heavy lifting of determining where, when, and how a user should receive a message across varying platforms.
Using PHP 8.4 readonly Data Transfer Objects (DTOs) and a powerful provider-driven feature mapping system, the core package operates completely agnostic to your application's user schema, relying on modern Notifiable contracts.
Building reliable notification architectures at scale is complex. This package solves the most daunting enterprise communication challenges out-of-the-box:
- 🏎️ Parallel Dispatching: Leverages Laravel 12's native
Concurrency::run()to fire simultaneous API requests to external providers (Twilio, Resend, WhatsApp) rather than blocking the execution thread sequentially. - 🚦 Smart Routing (Laravel Pennant): Prevents notification spam by utilizing Feature Flags. Instantly toggle broad channels (e.g. restrict
receive-whatsapptopremiumplan members only) directly from memory without bloatedif/elsechecks. - 🔕 Opt-Outs & Quiet Hours: Fully customizable User Preferences architecture. Users can selectively disable channels or define per-channel "Quiet Hours" (e.g. "Do not send SMS between 10 PM and 6 AM").
- 🪂 Automatic Fallback Resolution: If a primary channel fails (like a Push Notification to an offline device), the system gracefully intercepts the failure and falls back to a secondary channel (like Email).
- 📊 Real-time Telemetry (Laravel Pulse): Comes packed with custom Pulse Cards (
NotificationThroughputCard,FailedNotificationsCard) hooked natively into the dispatcher lifecycle to monitor platform stability. - ⚖️ Rate Limiting & Grouping: Built-in throttles to strictly govern the volume of outgoing requests per user per channel, alongside payload grouping algorithms to compact duplicated alerts.
We provide a highly expressive, builder-pattern API via the NotificationCenter Facade to streamline dispatching messages manually or within your system controllers.
use malikad778\NotificationCenter\Facades\NotificationCenter;
use malikad778\NotificationCenter\DTOs\NotificationPayload;
use malikad778\NotificationCenter\Enums\NotificationPriority;
$payload = new NotificationPayload(
title: 'Critical Security Alert',
body: 'A new login was detected from a new device.',
actionUrl: 'https://your-app.com/security/sessions'
);
// 1. Basic Smart Dispatch
// Automatically calculates the optimal allowed channels via Pennant & User Preferences
NotificationCenter::send(to: $user, notification: $payload)
->withPriority(NotificationPriority::Urgent) // Bypasses User Quiet Hours
->dispatch();
// 2. Strict Channel Overrides
// Ignore smart-routing and force the message through specific protocols
NotificationCenter::send(to: $user, notification: $payload)
->via(['sms', 'push'])
->dispatch();For massive user-base marketing or service alerts, the built-in Bulk Dispatcher safely queues operations onto Laravel's background workers.
$users = App\Models\User::where('plan', 'premium')->get()->all();
// Dispatches asynchronous batch jobs scaling safely to 10k+ users.
NotificationCenter::sendBulk(
users: $users,
payload: $payload,
channels: ['email'] // optional restricted channel lock
);This microservice ships with standard endpoints designed for seamless frontend consumption.
Users have total control over their notification flows.
PUT /api/notifications/preferences
Authorization: Bearer <sanctum_token>
{
"preferences": [
{
"channel": "sms",
"enabled": true,
"quiet_hours_start": "22:00",
"quiet_hours_end": "08:00"
},
{
"channel": "push",
"enabled": false
}
]
}Create interpolatable Database notifications on the fly.
POST /api/notifications/templates
Content-Type: application/json
{
"name": "Order Shipped",
"content": "Hello {{ name }}, your order #{{ order_id }} is on its way!"
}- Install Dependencies
composer install
- Environment Configuration
Ensure a robust Queue driver like Redis or Database is configured, then run:
php artisan migrate
- Run Analytics Dashboard
Visit
php artisan pulse:work
/pulsein your browser to observe live cluster traffic.
All channels, components, and schema integrations guarantee coverage via Pest.
php artisan testMIT
