Database Notifications

Database and Broadcast Notifications

The database channel stores the notification for an in-app bell. php artisan make:notifications-table and migrate create the table, and toDatabase() (or toArray()) returns the payload:

The database side of OrderStatusChangedPHP
public function toDatabase(object $notifiable): array
{
    return ['order_id' => $this->order->id, 'status' => $this->order->status];
}

A databaseType() method returning 'order-status' replaces the class name in type. After the notify() call, $customer->unreadNotifications()->count() returned 1, and $customer->unreadNotifications->markAsRead() brought it to 0 by filling read_at:

Output of 170
$ sudo mysql -E shop -e 'SELECT * FROM notifications'
*************************** 1. row ***************************
             id: 44af9ab3-1d6a-4404-b3d1-726d237fdfba
           type: order-status
notifiable_type: App\Models\Customer
  notifiable_id: 3
           data: {"order_id":3,"status":"shipped"}
        read_at: 2026-09-23 08:54:59

The recipient is polymorphic (Polymorphic Relations). The broadcast channel pushes the toArray() payload to the private channel App.Models.Customer.3, where Laravel Echo 1,360 's .notification() callback updates the page; it needs Reverb 2,157 or another broadcaster (Running Laravel Reverb).