@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
No comments yet. Be the first!
This will permanently delete your comment.