Skip to content

Livewire — Usage ​

Comment box by page_id ​

Use a stable string key so comments survive URL changes:

html
@php
    $pageId = 'post-'.$post->id; // or 'dashboard', 'page-about', …
@endphp

<livewire:livewire-comments::comments
    :key="'comments-'.$pageId"
    :pageId="$pageId"
/>

pageId and commentable are locked Livewire properties — set them when the component mounts (props), do not bind them to mutable UI state.

Prefer a deterministic :key (page id / model id). Avoid Str::uuid() as the Livewire key on every render — that remounts the component and loses state.

Comment box on an Eloquent model ​

  1. Whitelist the class:
php
// config/vgcomment.php
'allowed_commentable_types' => [
    \App\Models\Post::class,
],
  1. Pass the model:
html
<livewire:livewire-comments::comments
    :key="'comments-post-'.$post->id"
    :commentable="$post"
/>

You can combine pageId and commentable when your app needs both scopes; most apps use one or the other.

Nested replies ​

Replies share a root_id and nest by parent_id for deep indentation (same nestReplies() tree as Blade). Reply actions open a composer in context of the parent comment.

Composer, Markdown, uploads ​

Behavior matches Blade Comments:

ControlResult
PaperclipAttachment chips sent with the comment
Insert image / paste / dropInline Markdown ![…](url) in the content

Bold/italic helpers and server-side emphasis normalization apply the same way. See Blade — Usage for the dual-path detail.

Emoji & reactions ​

Full emoji picker for inserting into content and for reacting. Backend accepts any emoji type ≤ 32 characters; reaction_types in config is suggestions only.

Multiple boxes on one page ​

Give each instance a unique Livewire key and a unique pageId (or different models):

html
<livewire:livewire-comments::comments :key="'comments-a'" pageId="section-a" />
<livewire:livewire-comments::comments :key="'comments-b'" pageId="section-b" />

Minimal page ​

html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    @livewireStyles
    @commentStyles
</head>
<body>
    <livewire:livewire-comments::comments pageId="blog-1" />

    @livewireScripts
    @commentScripts
</body>
</html>

Admin ​

Moderators configured in moderation_users open:

/{prefix}/admin

See Admin panel.

MIT · Blade-first for 2.x · Livewire 4 supported