Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Livewire

Building a Comment System with Livewire v4

Create a nested comment system.

1 February 20261 min readLivewireاقرأ بالعربية

On this page

  1. Component

Build a comment system with replies.

Component

php
@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
All articles

Keep reading

  • Authorization in Livewire v4 Components1 February 20261 min read
  • Blaze Pre-Compiler: Massive Performance Gains in Livewire v41 February 20261 min read
  • Building a Bookmark Feature with Livewire v41 February 20261 min read