Files
relaticle-comments/raw/essentials/notifications.md
github-actions[bot] 7c9f000e60 Deploy 1.x docs
2026-03-27 11:03:10 +00:00

3.4 KiB

Notifications

Comment notifications, subscriptions, and real-time updates.

Notification Types

Two notification classes are included:

CommentRepliedNotification

Sent to all thread subscribers when a new comment or reply is posted. The comment author is excluded from receiving their own notification.

UserMentionedNotification

Sent to a user when they are @mentioned in a comment. Self-mentions are ignored.

Channels

// config/comments.php
'notifications' => [
    'channels' => ['database'],
    'enabled' => true,
],

Available channels: 'database' and 'mail'. Add both to send email notifications alongside database notifications:

'notifications' => [
    'channels' => ['database', 'mail'],
    'enabled' => true,
],

Subscriptions

Users can subscribe to comment threads on any commentable model. Subscribers receive notifications when new comments are posted.

Auto-Subscribe

'subscriptions' => [
    'auto_subscribe' => true,
],

When enabled:

  • Users are auto-subscribed when they post a comment
  • Users are auto-subscribed when they are @mentioned

Manual Subscription

Users can toggle their subscription using the subscribe/unsubscribe button in the comments UI.

Programmatic Access

use Relaticle\Comments\Models\Subscription;

// Check subscription status
Subscription::isSubscribed($commentable, $user);

// Subscribe/unsubscribe
Subscription::subscribe($commentable, $user);
Subscription::unsubscribe($commentable, $user);

// Get all subscribers for a commentable
$subscribers = Subscription::subscribersFor($commentable);

Events

<th>
  Trigger
</th>

<th>
  Broadcasts
</th>
<td>
  New comment or reply
</td>

<td>
  Yes
</td>
<td>
  Comment edited
</td>

<td>
  Yes
</td>
<td>
  Comment soft-deleted
</td>

<td>
  Yes
</td>
<td>
  Reaction added/removed
</td>

<td>
  Yes
</td>
<td>
  User @mentioned
</td>

<td>
  No
</td>
Event
CommentCreated
CommentUpdated
CommentDeleted
CommentReacted
UserMentioned

Real-time Updates

Broadcasting

Enable broadcasting for instant updates across browser sessions:

// config/comments.php
'broadcasting' => [
    'enabled' => true,
    'channel_prefix' => 'comments',
],

Events are broadcast on private channels: {prefix}.{commentable_type}.{commentable_id}

This requires Laravel Echo and a broadcasting driver (Pusher, Ably, etc.) configured in your application.

Polling Fallback

When broadcasting is disabled, the Livewire component polls for updates:

'polling' => [
    'interval' => '10s',
],

Set to null to disable polling entirely.

Disabling Notifications

'notifications' => [
    'enabled' => false,
],

This disables all notification dispatching. Subscriptions and events still work, but no notifications are sent.