Laravel Notifications System: Send Alerts via Mail, Database & More

Published: Jun 29, 2025 2 min read
Laravel Notifications Email Alerts Slack Real-time Database Notifications Laravel Tips User Experience

🔔 Introduction

Have you ever wanted to notify users after an action like a successful order or a password change? Laravel makes this super simple using its built-in Notification system. Whether it’s an email, database alert, or even a Slack message — Laravel’s elegant syntax makes it fun and scalable.


📌 Step 1: Create a Notification

bash
php artisan make:notification OrderShipped

This command creates a class under app/Notifications. It’s where you’ll define how the notification is sent (mail, database, etc.).


📩 Step 2: Sending via Mail

Update your notification like this:

php
public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { return (new MailMessage) ->subject('Your Order Has Shipped') ->line('We’re excited to let you know your order is on the way!') ->action('Track Order', url('/orders')) ->line('Thank you for shopping with us!'); }

🗃 Step 3: Save to Database

To store the notification in your database:

  1. Add 'database' to the via() method:

php
public function via($notifiable) { return ['mail', 'database']; }
  1. Then use toDatabase() method:

php
public function toDatabase($notifiable) { return [ 'message' => 'Your order has been shipped!', 'order_id' => $this->order->id, ]; }
  1. Don’t forget to run:

bash
php artisan notifications:table php artisan migrate

✅ Step 4: Triggering a Notification

From your controller:

php
$user->notify(new OrderShipped($order));

That’s it. Laravel handles the rest!


📥 Optional Channels: SMS, Slack, and Custom

Laravel supports:

  • Nexmo (SMS)

  • Slack

  • Custom channels (e.g., WhatsApp via API)

All of this using the same Notification structure.


🔐 Bonus Tip: Read/Unread Status

Laravel automatically tracks read_at timestamps so you can show unread badges like:

php
auth()->user()->unreadNotifications->count();

And mark them as read:

php
auth()->user()->unreadNotifications->markAsRead();

🧠 Conclusion

Laravel Notifications make it super easy to build user-friendly experiences. Instead of writing separate logic for emails or alerts, you can centralize it with clean code.

Start with a simple use case, and you’ll be amazed how scalable the system is.

Author
Paramjeet Yogi

Web Developer & Blogger passionate about Laravel and modern web development.