Home API Tools Posts Hire Me About
Sign In Create Account
Livewire

Building a Comment System with Livewire v4

February 01, 2026 1 min read 25 views

Build a comment system with replies.

Component

@php
new class extends Livewire\Component {
    public Post $post;
    public string $content = '';
    public ?int $replyingTo = null;
    
    public function addComment(): void
    {
        $this->validate(['content' => 'required|min:3']);
        
        $this->post->comments()->create([
            'content' => $this->content,
            'parent_id' => $this->replyingTo,
            'user_id' => auth()->id(),
        ]);
        
        $this->reset(['content', 'replyingTo']);
    }
}
@endphp
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!