with('post:id,slug,title')->orderByDesc('id'); if ($request->has('approved')) { $query->where('is_approved', $request->boolean('approved')); } return response()->json(['data' => $query->get()]); } /** * Approve or reject a comment. */ public function update(Request $request, int $id): JsonResponse { $validated = $request->validate([ 'is_approved' => ['required', 'boolean'], ]); $comment = Comment::findOrFail($id); $comment->is_approved = $validated['is_approved']; $comment->save(); return response()->json(['data' => $comment]); } /** * Delete a comment. */ public function destroy(int $id): JsonResponse { Comment::findOrFail($id)->delete(); return response()->json(null, 200); } }