Notifications
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.
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,
],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 cryptoBy 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.