Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AnswerController
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 storeCustomerAnswers
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Controllers\Api\V4;
4
5use App\Http\Controllers\Controller;
6use App\Http\Requests\Api\V4\StoreCustomerAnswers;
7use App\Models\Answer;
8use App\Models\Customer;
9use App\Models\Service;
10use Illuminate\Http\JsonResponse;
11
12class AnswerController extends Controller
13{
14    /**
15     * Store the customer answers.
16     *
17     * @param \App\Http\Requests\Api\V4\StoreCustomerAnswers $request
18     * @param \App\Models\Service                            $service
19     * @param \App\Models\Customer                           $customer
20     * @return \Illuminate\Http\JsonResponse
21     */
22    public function storeCustomerAnswers(
23        StoreCustomerAnswers $request,
24        Service $service,
25        Customer $customer
26    ): JsonResponse {
27        // * Make sure we are accessing a customer that belongs to our service.
28        $this->authorize('customerBelongsToService', $customer);
29
30        $existingAnswerIds = $customer->getAnswers($service)->pluck('id');
31        $answersID         = Answer::query()->whereIn('id', $request->answers)->pluck('id');
32        $customer->answers()->sync($answersID->merge($existingAnswerIds));
33        return response()->json();
34    }
35}