diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index d2308cc..124928b 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -17,6 +17,7 @@ class CommentController extends Controller public function index(Video $video) { $comments = $video->comments()->whereNull('parent_id')->with(['user', 'replies.user'])->get(); + return response()->json($comments); } @@ -35,12 +36,14 @@ class CommentController extends Controller // Handle mentions preg_match_all('/@(\w+)/', $request->body, $matches); - if (!empty($matches[1])) { + if (! empty($matches[1])) { // Mentions found - in production, you would send notifications here // For now, we just parse them } - return response()->json($comment->load('user')); + $video->increment('comment_count'); + + return response()->json(['success' => true, 'comment' => $comment->load('user')]); } public function update(Request $request, Comment $comment) @@ -67,6 +70,7 @@ class CommentController extends Controller } $comment->delete(); + return response()->json(['success' => true]); } } diff --git a/resources/views/components/video-comments.blade.php b/resources/views/components/video-comments.blade.php index fb55723..37cfa35 100644 --- a/resources/views/components/video-comments.blade.php +++ b/resources/views/components/video-comments.blade.php @@ -1,19 +1,24 @@
No comments yet. Be the first to - comment!
- @endforelse + @if (isset($video)) + @forelse($video->comments()->whereNull('parent_id')->with('user', 'replies.user')->latest()->limit(20)->get() as $comment) + @include('videos.partials.comment', ['comment' => $comment]) + @empty +No comments yet. Be the + first to comment!
+ @endforelse + @endifNo comments yet. Be the - first to comment!
- @endforelse -No comments yet. Be - the first to comment!
- @endforelse - @endif -No comments yet. Be - the first to comment!
- @endforelse - @endif -No comments yet. Be - the first to comment!
- @endforelse - @endif -No comments yet. Be the + first to comment!
+ @endforelse +
- Comments ({{ $video->comment_count }}) + Comments ({{ isset($video->comment_count) ? $video->comment_count : 0 }})
- @auth