ldc-crm/app/Http/Controllers/Api/V2/AnswerController.php

35 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-08-10 12:09:49 +02:00
<?php
namespace App\Http\Controllers\Api\V2;
use App\Http\Controllers\Controller;
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
{
/**
* 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 {
$this->authorize('customerBelongsToService', $customer);
$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));
return \response()->json();
}
2021-08-10 12:09:49 +02:00
}