> ## Documentation Index
> Fetch the complete documentation index at: https://docs.commentify.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# Realtime threads

> Broadcast approved comments and likes on commentify.{alias}.{id} with Laravel Reverb and Echo.

```env theme={null}
COMMENTIFY_REALTIME=true
```

```php theme={null}
'realtime' => [
    'enabled' => (bool) env('COMMENTIFY_REALTIME', false),
],
```

When enabled, **approved** new comments broadcast immediately (`ShouldBroadcastNow`). Pending comments do **not** broadcast. Likes broadcast via `CommentLikeObserver` as `.comment.liked`.

## Channel

Public channel name:

```
commentify.{alias}.{id}
```

`alias` is the `commentables` key when the morph class maps to one; otherwise the morph class string. Helpers: `RealtimeChannel::forModel($article)`, `RealtimeChannel::name($comment)`.

Events (leading dot is Echo's convention for broadcastAs without a namespace):

| Event              | Payload                                             |
| ------------------ | --------------------------------------------------- |
| `.comment.created` | `{ comment: { …same shape as the API resource… } }` |
| `.comment.liked`   | `{ id, likes_count }`                               |

## Echo

Point Laravel Echo at [Reverb](https://laravel.com/docs/reverb). Livewire includes a Pro realtime partial that refreshes the thread. React/Vue ingest events through `subscribeToThread()`:

```ts theme={null}
import { subscribeToThread } from "@commentify/core";

const stop = subscribeToThread(store, "articles", articleId, window.Echo);
// later:
stop();
```

If `window.Echo` (or the `echo` argument) is missing, the helper no-ops. The bundled `<CommentThread />` subscribes when `features.realtime` is true.

Remote creates go through `store.ingestRemoteComment()`. Remote likes through `store.applyRemoteLike(id, likes_count)` so you do not double-count the tab that performed the like.

Configure broadcasting, `reverb`, and Echo as you would for any Laravel app. Commentify does not start Reverb for you.
