{{-- ✅ DEFINE HELPER FUNCTION FIRST (before any HTML) --}} @php if (!function_exists('_renderComment')) { function _renderComment($comment, $video, $depth = 0) { $avatar = $comment->user->avatar_url ?? 'https://ui-avatars.com/api/?name=' . urlencode($comment->user->name ?? 'User') . '&background=ef4444&color=fff'; $isOwn = $comment->user_id === (auth()->id() ?? 0); $videoId = $video->id ?? 0; $html = '
'; $html .= '' .
                e($comment->user->name ?? 'User') .
                ''; $html .= '
'; $html .= '
'; $html .= '' . e($comment->user->name ?? 'User') . ''; $html .= '' . ($comment->created_at ? $comment->created_at->diffForHumans() : '') . ''; $html .= '
'; $html .= '
' . e($comment->body) . '
'; // Edit form (only for owner) if ($isOwn) { $html .= ''; } // Action buttons $html .= '
'; $html .= ''; if ($isOwn) { $html .= ''; $html .= ''; } $html .= '
'; // Reply form $html .= ''; // Nested replies (max depth 3) if ($comment->replies && $comment->replies->count() > 0 && $depth < 3) { $html .= '
'; foreach ($comment->replies as $reply) { $html .= _renderComment($reply, $video, $depth + 1); } $html .= '
'; } $html .= '
'; return $html; } } @endphp {{-- ✅ MAIN COMMENTS SECTION --}}

Comments ({{ $video->comment_count }})

@auth
{{ Auth::user()->name }}
@else
Sign in to comment
@endauth
@forelse($video->comments()->whereNull('parent_id')->with('user', 'replies.user')->latest()->get() as $comment) {!! _renderComment($comment, $video, 0) !!} @empty

No comments yet. Be the first to comment!

@endforelse
{{-- ✅ DELETE MODAL --}} {{-- ✅ TOAST NOTIFICATION --}} {{-- ✅ PREFIXED CSS --}} {{-- ✅ JAVASCRIPT --}}