34 lines
1 KiB
PHP
34 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V4;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V4\StoreCustomerAnswers;
|
|
use App\Models\Customer;
|
|
use App\Models\Question;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class AnswerController extends Controller
|
|
{
|
|
/**
|
|
* Store the customer answers.
|
|
*
|
|
* @param \App\Http\Requests\Api\V4\StoreCustomerAnswers $request
|
|
* @param \App\Models\Customer $customer
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function storeCustomerAnswers(
|
|
StoreCustomerAnswers $request,
|
|
Customer $customer
|
|
): JsonResponse {
|
|
// * Make sure we are accessing a customer that belongs to our service.
|
|
$this->authorize('customerBelongsToService', $customer);
|
|
|
|
$question = Question::find($request->validated('question'));
|
|
|
|
$customer->answers()->detach($question->answers);
|
|
$customer->answers()->attach($request->validated('answers'));
|
|
|
|
return response()->json();
|
|
}
|
|
}
|