symfony/notifier
Symfony Notifier lets your app send notifications through multiple channels like email, SMS, chat, and more. It provides a unified API, integrates with many third-party providers, and supports routing, transports, and message formatting for flexible delivery.
.env for DSN-based transports).Notifiable trait) and Symfony Messenger for async processing.notifier.dsn=slack://token@channel) for zero-boilerplate setup.| Risk Area | Mitigation Strategy |
|---|---|
| Channel-Specific Quirks | Use Symfony’s transport factories and fallback mechanisms (e.g., retry SMS if email fails). |
| Rate Limiting | Implement circuit breakers (e.g., Laravel’s Throttle) per channel. |
| Template Complexity | Standardize on Blade/Twig and validate templates via Laravel’s validation rules. |
| Legacy Systems | Wrap existing notification logic in adapters (e.g., LegacyEmailNotifier). |
| Cost Overruns | Monitor usage via Symfony’s SentMessage events and set budget alerts. |
SentMessage to track opt-outs.config/services.php or Laravel’s bind().Notifiable trait or use Symfony’s NotificationEvent.autoconfigure for transports.Mail::send() or Http::post() calls with Symfony Notifier.// Before (Custom)
Mail::send([], [], function ($message) {
$message->to('user@example.com')->subject('Alert')->line('Hello!');
});
// After (Notifier)
$notifier = app(NotifierInterface::class);
$notifier->send(new EmailNotification('user@example.com', 'Hello!'));
TwilioTransport, SlackTransport).SmsNotification->EmailNotification).| Component | Compatibility Notes |
|---|---|
| Laravel Notifications | Use Symfony\Notifier\Bridge\Laravel\Notification to bridge Laravel’s Notifiable. |
| Laravel Queues | Notifier messages are serialized and processed by Laravel’s queue workers. |
| Laravel Events | Extend Symfony\Component\Notifier\Notification\NotificationSentEvent. |
| Custom Transports | Extend Symfony\Component\Notifier\Transport\TransportInterface for proprietary channels. |
| Third-Party APIs | Use DSN-based config (e.g., slack://token@channel) for easy swapping. |
composer require symfony/notifier..env (e.g., NOTIFIER_DSN=slack://token@channel).config/services.php:
'notifier' => [
'dsns' => [
'slack' => env('NOTIFIER_DSN_SLACK'),
'email' => env('NOTIFIER_DSN_EMAIL'),
],
],
SlackAlertNotification, SmsOrderUpdateNotification).TransportTestCase or Laravel’s MockHttp for unit tests.SentMessage events to a database or monitoring tool (e.g., Datadog)..env or config/services.php.SentMessage events.Throttle middleware to avoid API abuse.| Failure Scenario | Mitigation |
|---|---|
| Channel Outage | Implement fallback chains (e.g., SMS → Email → Slack). |
| Queue Backlog |
How can I help you explore Laravel packages today?