storeCustomerAnswers Mise à jour sans supprimer les anciennes questions

This commit is contained in:
Jérémy Munsch 2021-08-18 08:27:09 +02:00
parent 4527bc01f6
commit f8a61d0e4c

View file

@ -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();
}
}