Modern web apps leverage notifications for communication with end-users. Whether you want to alert users about a new order, password reset, payment confirmation, or system update, Laravel Notifications make it simple to send alerts. In addition to support for sending email, Laravel provides support for sending notifications across a variety of delivery channels, including email, SMS (via Vonage, formerly known as Nexmo), and Slack. In addition, a variety of community-built notification channels have been created to send notifications over dozens of different channels! Notifications may also be stored in a database so they may be displayed in your web interface.
Through this blog post, we will learn how to send both Database Notifications and Email Notifications in Laravel.

Prerequisites:
Before starting, make sure:
- The database is configured
- Mail settings have been configured properly in your .env file
Steps to Send Database and Email Notifications in Laravel:
Step 1: Create the Notifications Table
To create a table in your database for storing notifications, simply run the following command:
php artisan notifications:tableThen run the following command to migrate your new notifications table:
php artisan migrateThis will create a new notifications table with all of the required columns including `type`, `notifiable_id`, and `data` to store your alerts.
Step 2: Create a Notification Class
Next, we need to create a Notification class. For this example, let’s suppose we want to create a Notification that will notify the user when their order ships.
To do this, we will run the following command:
php artisan make:notification OrderShippedAfter our Notification class has been created, you will find a new file located at `app/Notifications/OrderShipped.php`. Inside this file, we will want to update three of the methods: `via`, `toMail`, and `toArray’.
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class OrderShipped extends Notification
{
use Queueable;
public $order_id;
// Constructor to pass data
public function __construct($order_id)
{
$this->order_id = $order_id;
}
// Specify delivery channels
public function via($notifiable)
{
return ['mail', 'database'];
}
// Design the Email
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Your Order is Shipped!')
->greeting('Hello ' . $notifiable->name . ',')
->line('Good news! Your order #' . $this->order_id . ' has been shipped.')
->action('Track Order', url('/orders/' . $this->order_id))
->line('Thank you for shopping with us!');
}
// Design the Database Notification
public function toArray($notifiable)
{
return [
'order_id' => $this->order_id,
'message' => 'Order #' . $this->order_id . ' has been shipped.',
'link' => url('/orders/' . $this->order_id),
];
}
}Step 3: Trigger the Notification
Now, let’s send this notification. You can do this from a Controller, a Route, or an Event.
Open your Controller (e.g., `OrderController.php`) and add the following logic:
use App\Models\User;
use App\Notifications\OrderShipped;
use Illuminate\Support\Facades\Notification;
public function shipOrder($id)
{
$user = User::find(1); // Find the user to notify
$order_id = $id;
// Method 1: Using the Notifiable trait (Preferred)
$user->notify(new OrderShipped($order_id));
// Method 2: Using the Notification Facade (For multiple users)
// Notification::send($users, new OrderShipped($order_id));
return back()->with('success', 'Notification sent successfully!');
}Step 4: Display Notifications in Blade View
To show the notifications (like a Facebook-style bell icon), we can loop through the user’s notifications in our Blade file.
Open your layout file (e.g., `resources/views/layouts/app.blade.php`) and add this dropdown menu:
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs- toggle="dropdown">
Notifications <span class="badge bg-danger">{{ auth()→user()→unreadNotifications- >count() }}</span>
</a>
<div class="dropdown-menu dropdown-menu-end">
@forelse(auth()->user()->unreadNotifications as $notification)
<a class="dropdown-item" href="{{ $notification->data['link'] }}">
{{ $notification->data['message'] }}
<br>
<small class="text-muted">{{ $notification->created_at->diffForHumans() }}</small>
</a>
<div class="dropdown-divider"></div>
@empty
<a class="dropdown-item" href="#">No new notifications</a>
@endforelse
@if(auth()->user()->unreadNotifications->count() > 0)
<a href="{{ route('markAsRead') }}" class="dropdown-item text-center text- primary">Mark all as Read</a>
@endif
</div>
</li>Step 5: Mark Notifications as Read
Finally, we need a route to mark notifications as “read” so the badge count disappears.
Route (`routes/web.php`):
Route::get('/mark-as-read', [App\Http\Controllers\HomeController::class, 'markAsRead'])→name('markAsRead');
Controller (`HomeController.php`):
public function markAsRead()
{
auth()->user()->unreadNotifications->markAsRead();
return back();
}Conclusion:
That’s it! You have successfully implemented a complete notification system in Laravel.
- Emails are sent to the user’s inbox.
- Database alerts appear instantly in their dashboard.
This provides users with better engagement, as well as allowing them to be made aware of things that are important to them.

FAQ
1. What is the difference between Mail and Database notifications in Laravel?
- Mail notification sends an email to the user.
- Database notification stores the notification inside the notifications table so it can be displayed inside the app.
2. Can I send notifications to multiple channels at once?
Yes. Just return multiple channels inside the via() method:
return ['mail', 'database'];3. How do I retrieve only unread notifications?
auth()->user()->unreadNotifications;4. How do I mark all notifications as read?
auth()->user()->unreadNotifications->markAsRead();5. Is it necessary to use queues for notifications?
While it is not a requirement, it is highly recommended for production applications in order to help maintain performance and scalability.



