where('task_id', $taskId)->find($commentId); return $model === null ? null : $this->toEntity($model); } public function save(TaskComment $comment): TaskComment { $model = $comment->id() === null ? new TaskCommentModel : TaskCommentModel::query()->findOrFail($comment->id()); $model->fill([ 'task_id' => $comment->taskId(), 'user_id' => $comment->authorId(), 'body' => $comment->body()->value, 'edited_at' => $comment->editedAt(), 'created_at' => $comment->createdAt(), ])->save(); return $this->toEntity($model->refresh()); } public function delete(TaskComment $comment): void { TaskCommentModel::query()->whereKey($comment->id())->delete(); } private function toEntity(TaskCommentModel $model): TaskComment { return TaskComment::reconstitute( $model->id, $model->task_id, $model->user_id, new TaskCommentBody($model->body), DateTimeImmutable::createFromInterface($model->created_at), $model->edited_at === null ? null : DateTimeImmutable::createFromInterface($model->edited_at), ); } }