comments()->orderBy('created_at')->get(); return TaskCommentResource::collection($comments); } /** * Create a new comment for a task. */ public function store(StoreTaskCommentRequest $request, Task $task) { $comment = $task->comments()->create($request->validated()); return (new TaskCommentResource($comment)) ->response() ->setStatusCode(201); } /** * Update a comment. */ public function update(Request $request, TaskComment $comment) { $request->validate([ 'body' => ['required', 'string'], ]); $comment->update([ 'body' => $request->string('body'), ]); return new TaskCommentResource($comment); } /** * Show a single comment. */ public function show(TaskComment $comment) { return new TaskCommentResource($comment); } /** * Delete a comment. */ public function destroy(TaskComment $comment) { $comment->delete(); return response()->noContent(); } }