diff --git a/app/Http/Controllers/Api/V2/AnswerController.php b/app/Http/Controllers/Api/V2/AnswerController.php index 86bda2f..d752147 100644 --- a/app/Http/Controllers/Api/V2/AnswerController.php +++ b/app/Http/Controllers/Api/V2/AnswerController.php @@ -23,8 +23,9 @@ class AnswerController extends Controller public function storeCustomerAnswers(StoreCustomerAnswers $request, Service $service, Customer $customer): JsonResponse { $this->authorize('customerBelongsToService', $customer); - $answersID = Answer::whereIn('id', $request->answers)->pluck('id')->toArray(); - $customer->answers()->sync($answersID); + $existingAnswerIds = $customer->getAnswers($service)->pluck('id'); + $answersID = Answer::whereIn('id', $request->answers)->pluck('id'); + $customer->answers()->attach($answersID->diff($existingAnswerIds)); return \response()->json(); } }