NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

Opt in to bridge new messages to Laravel notifications. When enabled, every sent message notifies the thread’s other notifiable participants — the sender is never notified, and participants without Laravel’s Notifiable trait are skipped:

MESSAGES_NOTIFICATIONS=true
// config/messages.php
'notifications' => [
    'enabled' => env('MESSAGES_NOTIFICATIONS', false),
    'notification' => RoundlyConsulting\Messages\Notifications\NewMessageNotification::class,
    'channels' => ['database'],   // mail is never forced
],

The default notification

RoundlyConsulting\Messages\Notifications\NewMessageNotification is queued (ShouldQueue), delivers via notifications.channels, and implements toArray() with:

  • message_id and thread_id,
  • preview — the message’s truncated, type-aware preview,
  • sender_id and sender_type — the sender’s class basename (User), resolved through the morph map and never its class name; null for a system message.

The same array is the database and the broadcast payload. It implements no toMail(), so mail needs your own class.

Customising

To customise channels and content, publish an editable copy of the default and point the config at it — the copy lives in your app namespace and starts out behaving exactly like the package’s notification:

php artisan vendor:publish --tag="messages-notifications"
# → app/Notifications/Messages/NewMessageNotification.php (App\Notifications\Messages)
// config/messages.php
'notifications' => [
    'notification' => App\Notifications\Messages\NewMessageNotification::class,
],

A copy published by 1.1.x or earlier still puts the sender’s morph type in sender_type — the full class name (App\Models\User) on an app without a morph map. Re-publish it with --force, which overwrites your edits, or copy the sender_type code over from the package’s notification.

Or point notifications.notification at a class of your own — it is constructed with the sent Message, so extending the default works too:

use RoundlyConsulting\Messages\Notifications\NewMessageNotification;

class ChatMessageReceived extends NewMessageNotification
{
    // $this->message is the sent Message — override via() or toArray(), or add toMail()
}

// config/messages.php
'notification' => App\Notifications\ChatMessageReceived::class,

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.