Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
5 / 5
AnswerController
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 storeCustomerAnswers
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
1<?php
2
3namespace App\Http\Controllers\Api\V2;
4
5use App\Http\Controllers\Controller;
6use App\Http\Requests\Api\V2\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  StoreCustomerAnswers $request
18     * @param  Service              $service
19     * @param  Customer             $customer
20     * @return 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::whereIn('id', $request->answers)->pluck('id');
32        $customer->answers()->sync($answersID->merge($existingAnswerIds));
33        return response()->json();
34    }
35}