Challenge 2 — Solution Task: Write a destroy(string $id) method for PostApiController that deletes a post by ID and returns a 204 status with an empty body on success, or a 404 JSON error if the post doesn't exist (using the Post class's find() method first to check, catching PostNotFoundException). find((int)$id); } catch (PostNotFoundException $e) { jsonResponse(['error' => 'Post not found'], 404); } $post->delete((int)$id); http_response_code(204); exit; } } ?> Output (success case, deleting an existing post): (HTTP 204 status, completely empty response body — no JSON at all) Output (post doesn't exist): {"error":"Post not found"} (sent with HTTP 404 status) Notes: - find() is deliberately called FIRST, purely to confirm the post actually exists before attempting the delete - this mirrors the chapter's own show() method's use of find() to trigger PostNotFoundException, reused here for the same existence check rather than duplicating that logic. - The success path deliberately does NOT call jsonResponse() at all, since a 204 No Content response is defined as having no body - http_response_code(204) followed directly by exit sends the correct empty response, matching this chapter's own status-code table entry for 204. - delete() itself (from the Post class, written back in the Intermediate capstone) is only ever reached once find() has already confirmed the post exists, avoiding a delete attempt against a row that was never there to begin with.