2021-08-10 12:09:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V2;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2021-08-11 17:25:24 +02:00
|
|
|
use App\Http\Requests\Api\V2\StoreCustomerAnswers;
|
|
|
|
|
use App\Models\Answer;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\Service;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2021-08-10 12:09:49 +02:00
|
|
|
|
|
|
|
|
class AnswerController extends Controller
|
|
|
|
|
{
|
2021-08-11 17:25:24 +02:00
|
|
|
/**
|
|
|
|
|
* Store the customer answers
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Api\V2\StoreCustomerAnswers $request
|
|
|
|
|
* @param \App\Models\Service $service
|
|
|
|
|
* @param \App\Models\Customer $customer
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
2021-08-23 20:00:44 +02:00
|
|
|
public function storeCustomerAnswers(
|
|
|
|
|
StoreCustomerAnswers $request,
|
|
|
|
|
Service $service,
|
|
|
|
|
Customer $customer
|
|
|
|
|
): JsonResponse {
|
2021-08-11 17:25:24 +02:00
|
|
|
$this->authorize('customerBelongsToService', $customer);
|
2021-08-18 08:27:09 +02:00
|
|
|
$existingAnswerIds = $customer->getAnswers($service)->pluck('id');
|
|
|
|
|
$answersID = Answer::whereIn('id', $request->answers)->pluck('id');
|
2021-08-18 11:56:01 +02:00
|
|
|
$customer->answers()->sync($answersID->merge($existingAnswerIds));
|
2021-08-11 17:25:24 +02:00
|
|
|
return \response()->json();
|
|
|
|
|
}
|
2021-08-10 12:09:49 +02:00
|
|
|
}
|