Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

benjamincrozat/blog-v5

126 stars
3 code files
View benjamincrozat/blog-v5 on GitHub

app/Livewire/Comments.php

Open in GitHub
use App\Models\Comment;
use Livewire\Component;
use Illuminate\View\View;
 
class Comments extends Component
{
public int $postId;
 
public function render() : View
{
return view('livewire.comments', [
'comments' => Comment::query()
->where('post_id', $this->postId)
->whereNull('parent_id')
->paginate(30),
'commentsCount' => Comment::query()
->where('post_id', $this->postId)
->count(),
]);
}
}

resources/views/livewire/comments.blade.php

Open in GitHub
<div>
<h1 class="font-bold tracking-widest text-center text-black uppercase">
{{ trans_choice(':count comment|:count comments', $commentsCount) }}
</h1>
 
<div class="grid gap-8 mt-8">
@foreach ($comments as $comment)
<x-comment :$comment />
@endforeach
</div>
</div>

resources/views/posts/show.blade.php

Open in GitHub
// ...
 
<x-section
id="comments"
class="mt-12 md:mt-16 lg:max-w-(--breakpoint-md)"
>
<livewire:comments :post-id="$post->id" />
</x-section>
 
// ...

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.