ldc-crm/app/Http/Controllers/Api/V2/AnswerController.php
Alexis Gousseau 303834bbca
Crm V4
- Make all tests pass Client (V4),CRMV2,CRMV4
- Simplify client submodule path
- Move App_url to .env.testing
2023-10-06 16:37:29 +02:00

35 lines
1.2 KiB
PHP

<?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;
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
*/
public function storeCustomerAnswers(
StoreCustomerAnswers $request,
Service $service,
Customer $customer
): JsonResponse {
// * Make sure we are accessing a customer that belongs to our service.
$this->authorize('customerBelongsToService', $customer);
$existingAnswerIds = $customer->getAnswers($service)->pluck('id');
$answersID = Answer::query()->whereIn('id', $request->answers)->pluck('id');
$customer->answers()->sync($answersID->merge($existingAnswerIds));
return response()->json();
}
}