/laravel-agent:notification:make
Create multi-channel notification (55+ channels)
Overview
The /notification:make command creates Laravel notifications with support for 55+ notification channels. It can generate complete multi-channel notification classes or setup individual channels with all required dependencies, configuration, and routing methods.
Usage
/laravel-agent:notification:make [NotificationName] [--channels=] [--setup=]
Examples
# Create notification with multiple channels
/laravel-agent:notification:make OrderShipped --channels=mail,telegram
# Setup a channel only (no notification class)
/laravel-agent:notification:make --setup=telegram
# Create notification with popular channels
/laravel-agent:notification:make WelcomeUser --channels=mail,discord,twilio
# Create admin alert notification
/laravel-agent:notification:make AlertAdmin --channels=slack,teams
Operating Modes
The command operates in two distinct modes:
Mode 1: Setup Channel Only
Use --setup=<channel> to install and configure a notification channel without creating a notification class. This is useful when you want to prepare your application for a specific channel before creating notifications.
Mode 2: Create Notification
Provide a notification name to create a complete notification class with support for multiple channels. The command automatically installs required packages, configures routing, and sets up environment variables.
Supported Channels
The command supports 55+ notification channels, organized into categories:
Built-in Channels (No Package Required)
| Channel | Description | Environment Variables |
|---|---|---|
| Email notifications | MAIL_* |
|
| database | Store in database | (migration required) |
| broadcast | WebSocket notifications | BROADCAST_DRIVER |
| slack | Slack webhooks | SLACK_WEBHOOK_URL |
Push Notifications
| Channel | Package | Environment Variables |
|---|---|---|
| telegram | laravel-notification-channels/telegram |
TELEGRAM_BOT_TOKEN |
| discord | laravel-notification-channels/discord |
DISCORD_WEBHOOK_URL |
| fcm | laravel-notification-channels/fcm |
FCM_SERVER_KEY |
| onesignal | laravel-notification-channels/onesignal |
ONESIGNAL_APP_ID, ONESIGNAL_REST_API_KEY |
| webpush | laravel-notification-channels/webpush |
VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY |
| apn | laravel-notification-channels/apn |
APN_KEY_ID, APN_TEAM_ID |
SMS/Voice
| Channel | Package | Environment Variables |
|---|---|---|
| twilio | laravel-notification-channels/twilio |
TWILIO_SID, TWILIO_TOKEN, TWILIO_FROM |
| vonage | laravel/vonage-notification-channel |
VONAGE_KEY, VONAGE_SECRET |
| messagebird | laravel-notification-channels/messagebird |
MESSAGEBIRD_ACCESS_KEY |
| plivo | laravel-notification-channels/plivo |
PLIVO_AUTH_ID, PLIVO_AUTH_TOKEN |
Messenger/Chat
| Channel | Package | Environment Variables |
|---|---|---|
| teams | laravel-notification-channels/microsoft-teams |
(webhook per notification) |
| googlechat | laravel-notification-channels/google-chat |
(webhook per notification) |
| rocketchat | laravel-notification-channels/rocket-chat |
ROCKETCHAT_URL |
Channel Configuration Examples
Here are configuration examples for popular notification channels:
Telegram
Environment configuration:
TELEGRAM_BOT_TOKEN=your-bot-token
User model routing method:
<?php
// In App\Models\User
public function routeNotificationForTelegram(): ?string
{
return $this->telegram_chat_id;
}
Discord
Environment configuration:
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
Twilio (SMS)
Environment configuration:
TWILIO_SID=your-account-sid
TWILIO_TOKEN=your-auth-token
TWILIO_FROM=+1234567890
User model routing method:
<?php
// In App\Models\User
public function routeNotificationForTwilio(): ?string
{
return $this->phone;
}
FCM (Firebase Cloud Messaging)
Environment configuration:
FCM_SERVER_KEY=your-server-key
FCM_SENDER_ID=your-sender-id
User model routing method:
<?php
// In App\Models\User
public function routeNotificationForFcm(): array
{
return $this->fcm_tokens()->pluck('token')->toArray();
}
WebPush
Environment configuration:
VAPID_PUBLIC_KEY=your-public-key
VAPID_PRIVATE_KEY=your-private-key
VAPID_SUBJECT=mailto:admin@yoursite.com
Generate VAPID keys:
php artisan webpush:vapid
OneSignal
Environment configuration:
ONESIGNAL_APP_ID=your-app-id
ONESIGNAL_REST_API_KEY=your-rest-api-key
Vonage (SMS)
Environment configuration:
VONAGE_KEY=your-key
VONAGE_SECRET=your-secret
VONAGE_SMS_FROM=YourApp
What Gets Created
Depending on the mode, the command creates different components:
Setup Mode Output
| Component | Location | Description |
|---|---|---|
| Package Installation | composer.json |
Channel-specific package via Composer |
| Configuration | config/ |
Published channel configuration file |
| Environment Variables | .env.example |
Required environment variables added |
| Routing Method | app/Models/User.php |
Channel routing method added |
| Migration | database/migrations/ |
User identifier field migration (if needed) |
Notification Creation Output
| Component | Location | Description |
|---|---|---|
| Notification Class | app/Notifications/ |
Multi-channel notification with via() and channel methods |
| Packages | composer.json |
All required channel packages installed |
| Environment Setup | .env.example |
All required credentials documented |
| Queue Configuration | Notification class | Implements ShouldQueue for async delivery |
Generated Notification Example
Here's an example of a multi-channel notification created by the command:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Telegram\TelegramMessage;
use NotificationChannels\Discord\DiscordMessage;
class OrderShipped extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public $order
) {}
public function via($notifiable): array
{
return ['mail', 'telegram', 'discord'];
}
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->subject('Your Order Has Shipped!')
->line('Order #' . $this->order->id . ' has been shipped.')
->action('Track Order', url('/orders/' . $this->order->id))
->line('Thank you for your purchase!');
}
public function toTelegram($notifiable): TelegramMessage
{
return TelegramMessage::create()
->content('*Order Shipped*')
->line('Your order #' . $this->order->id . ' has been shipped!')
->button('Track Order', url('/orders/' . $this->order->id));
}
public function toDiscord($notifiable): DiscordMessage
{
return DiscordMessage::create()
->embed(function ($embed) {
$embed->title('Order Shipped')
->description('Order #' . $this->order->id)
->url(url('/orders/' . $this->order->id))
->timestamp(now());
});
}
}
Interactive Prompts
When run without the --channels flag, the command provides interactive prompts:
- Notification name - Text input for the notification class name
- Select channels - Multi-select from available channels (Mail selected by default)
- Queue notifications? - Choose between queued (recommended for external channels) or synchronous delivery
- Add user preferences? - Optionally create a per-user channel preferences system
Usage Examples
After creating a notification, use it in your application:
<?php
// Send to a single user
$user->notify(new OrderShipped($order));
// Send to multiple users
Notification::send($users, new OrderShipped($order));
// Send to specific channels only
$user->notify((new OrderShipped($order))->onlyChannels(['mail', 'telegram']));
Process Flow
The command follows a systematic process:
For Setup Mode
- Install the channel package via Composer
- Publish channel configuration files
- Add environment variables to .env.example
- Add routing method to User model
- Create migration for user identifier field (if needed)
For Notification Creation
- Parse requested channels from flag or interactive prompt
- Check for and install required packages for each channel
- Invoke laravel-queue agent to generate notification class
- Generate via() method and channel-specific methods (toMail(), toTelegram(), etc.)
- Add all required environment variables to .env.example
Best Practices
- Use queueing - Always queue notifications to external services to prevent blocking requests
- Handle failures gracefully - Implement proper error handling for channel delivery failures
- Respect user preferences - Allow users to control which channels they receive notifications on
- Test thoroughly - Test each channel independently before deploying to production
- Monitor delivery - Track notification delivery rates and failures
- Use staging credentials - Test with staging/sandbox credentials before using production keys
Related Commands
- /laravel-agent:queue:setup - Setup queue infrastructure for notifications
- /laravel-agent:model:make - Create models that can receive notifications
- /laravel-agent:migration:make - Create migrations for channel identifiers