findOrFail($commentId); if ($request->user()->id !== $post->user_id) { abort(403, 'Only the post owner can highlight comments.'); } DB::transaction(function () use ($post, $comment) { // Remove any existing highlight on this post PostComment::where('post_id', $post->id) ->where('is_highlighted', true) ->update(['is_highlighted' => false]); $comment->update(['is_highlighted' => true]); }); return response()->json(['message' => 'Comment highlighted.', 'comment_id' => $comment->id]); } public function unhighlight(Request $request, int $postId, int $commentId): JsonResponse { $post = Post::findOrFail($postId); $comment = PostComment::where('post_id', $postId)->findOrFail($commentId); if ($request->user()->id !== $post->user_id) { abort(403, 'Only the post owner can remove comment highlights.'); } $comment->update(['is_highlighted' => false]); return response()->json(['message' => 'Highlight removed.', 'comment_id' => $comment->id]); } }