commentOrder->apply( $this->commentFilter->apply($post->comments()->getQuery(), $filters), $orderDef )->paginate($this->paginate); return PaginableResource::createFromLengthAwarePaginator($comments); } public function storeComment(array $data, int $postId): ?Comment { $post = Post::findOrFail($postId); $comment = $post->comments()->create([ 'content' => $data['content'], ]); return Comment::findOrFail($comment->id); } public function deleteComment(int $remoteId, int $id): bool { $post = Post::find($remoteId); if ($post === null) { return false; } $comment = $post->comments()->find($id); if ($comment === null) { return false; } return $comment->delete(); } public function updateComment(array $data, int $remoteId, int $id): ?Comment { $post = Post::find($remoteId); if ($post === null) { return null; } $comment = $post->comments()->find($id); if ($comment === null) { return null; } $comment->update($data); return Comment::findOrFail($comment->id); } }