tylercd100/laravel-notify
Laravel Notify adds a simple notification layer for Laravel, sending messages through Monolog-backed channels like email, Slack, Pushover, SMS (Twilio/Plivo), Sentry, Mailgun, Flowdock, Fleep, and more. Includes config publishing and Laravel 5.1–8 support.
Installation:
composer require tylercd100/laravel-notify
php artisan vendor:publish --provider="Tylercd100\Notify\Providers\NotifyServiceProvider"
config/notify.php for channel configuration.First Use Case: Send a basic log message to all configured channels (e.g., Slack, Email):
use Tylercd100\Notify\Facades\Notify;
Notify::info("User created successfully", ['user_id' => 123]);
info with debug, warning, error, etc., based on severity.Channel-Specific Usage:
Add channel aliases to config/app.php (e.g., "Slack" => Tylercd100\Notify\Facades\Slack::class).
Use directly:
Slack::warning("Database connection failed!");
Log-Level Routing:
debug, info, warning, error, etc.) to route messages to specific channels.notify.php to send error messages to Slack but debug messages only to logs.Contextual Data:
Notify::error("Failed to process payment", ['user_id' => 456, 'amount' => 99.99]);
Channel-Specific Facades:
Pushover::critical()).Plivo).Event-Driven Notifications:
public function handle(InvoicePaid $event) {
Notify::info("Invoice #{$event->invoice->id} paid", ['user' => $event->user]);
}
Conditional Notifications:
if (config('notify.channels.slack.enabled')) {
Slack::info("New user registered");
}
Monolog Compatibility:
StreamHandler for local logs) alongside laravel-notify.notify.php handler:
'handlers' => [
'slack' => [
'driver' => 'slack',
'webhook_url' => env('SLACK_WEBHOOK_URL'),
],
'log' => [
'driver' => 'monolog',
'path' => storage_path('logs/notify.log'),
],
],
Environment-Specific Config:
.env variables for sensitive data (e.g., SLACK_WEBHOOK_URL).notify.php per environment (e.g., config/notify-staging.php).Testing:
$this->mock(Notify::class)->shouldReceive('info')->once();
Notify::shouldReceive() for channel-specific assertions.Deprecated Features:
Context Formatting:
sms_limit in notify.php:
'sms_limit' => 160, // Default for Twilio/Plivo
Email Content-Type:
text/html is set for emails (fixed in v1.8.2+). If using custom templates, verify the LineFormatter in config/notify.php:
'formatters' => [
'line' => \Monolog\Formatter\LineFormatter::class,
],
Facade Aliases:
config/app.php will cause ClassNotFound errors for Slack, Pushover, etc.Rate Limiting:
notify.php to batch or debounce:
'slack' => [
'driver' => 'slack',
'rate_limit' => 5, // Messages per minute
],
Log Inspection:
storage/logs/laravel.log for unhandled exceptions or malformed messages.notify.php:
'debug' => env('APP_DEBUG', false),
Channel-Specific Issues:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Test"}' $SLACK_WEBHOOK_URL
Mailgun facade for API-based emails:
Mailgun::send('welcome@example.com', 'Hello from Mailgun!');
Context Serialization:
Notify::info("User data", ['role' => $user->role->name]); // OK
Notify::info("User data", ['role' => $user->role]); // May fail
Custom Handlers:
Tylercd100\Notify\Handlers\BaseHandler to add new channels (e.g., Discord, Telegram).config/notify.php:
'handlers' => [
'discord' => [
'driver' => 'discord',
'webhook_url' => env('DISCORD_WEBHOOK_URL'),
],
],
Formatter Overrides:
LineFormatter with a custom formatter (e.g., for JSON output):
'formatters' => [
'json' => \Monolog\Formatter\JsonFormatter::class,
],
Middleware:
// app/Providers/NotifyServiceProvider.php
public function boot() {
Notify::extend('custom', function($app) {
return new CustomHandler($app['log']);
});
}
Queueing:
database or redis) for async processing:
// config/notify.php
'queue' => 'high',
NotifyJob implementation.How can I help you explore Laravel packages today?