@props(['video']) @php use App\Models\CommentLike; $currentUserId = Auth::id() ?? 0; $topComments = $video->comments()->whereNull('parent_id')->with('user', 'replies.user')->latest()->get(); $commentCount = $topComments->sum(fn($c) => 1 + $c->replies->count()); $allCommentIds = $topComments->pluck('id') ->merge($topComments->flatMap(fn($c) => $c->replies->pluck('id'))) ->all(); $likeCounts = CommentLike::whereIn('comment_id', $allCommentIds) ->selectRaw('comment_id, COUNT(*) as cnt') ->groupBy('comment_id') ->pluck('cnt', 'comment_id'); $userLikedIds = $currentUserId ? CommentLike::where('user_id', $currentUserId) ->whereIn('comment_id', $allCommentIds) ->pluck('comment_id')->flip()->all() : []; if (!function_exists('ytcAvatar')) { function ytcAvatar($user) { if (!$user) return 'https://ui-avatars.com/api/?name=User&background=333&color=fff'; return $user->avatar_url ?? ('https://ui-avatars.com/api/?name='.urlencode($user->name ?? 'User').'&background=333&color=fff'); } } if (!function_exists('ytcTime')) { function ytcTime($dt) { if (!$dt) return ''; return $dt->diffForHumans(); } } @endphp
{{-- ── Header ── --}}
{{ number_format($commentCount) }} Comments
Top comments
Newest first
{{-- ── New comment form ── --}} @auth
{{ Auth::user()->name }}
@else
Sign in to leave a comment
@endauth {{-- ── Comments list ── --}}
@forelse($topComments as $comment) @php $isOwn = $comment->user_id === $currentUserId; @endphp
{{ $comment->user->name ?? 'User' }}
{{ $comment->user->name ?? 'User' }} {{ ytcTime($comment->created_at) }}
{{ $comment->body }}
{{-- Edit form --}} @if($isOwn) @endif {{-- Action bar --}}
@php $cLikes = $likeCounts->get($comment->id, 0); $cLiked = isset($userLikedIds[$comment->id]); @endphp @auth @endauth @if($isOwn)
@endif
{{-- Reply form --}} @auth
{{ Auth::user()->name }}
@endauth {{-- Replies --}} @if($comment->replies && $comment->replies->count() > 0)
@endif
@empty

No comments yet. Be the first!

@endforelse
{{-- ── Delete confirm modal ── --}}

Delete comment?

This will permanently delete your comment.