47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Screening;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
final class UpdateScreeningRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->route('screening')->user_id === auth()->id();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'answers' => ['required', 'array', 'size:10'],
|
|
'answers.*' => ['required', 'string', 'in:yes,no'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Custom validation messages.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'answers.required' => 'All screening questions must be answered.',
|
|
'answers.array' => 'Answers must be provided as an array.',
|
|
'answers.size' => 'All 10 screening questions must be answered.',
|
|
'answers.*.required' => 'Each screening question must have an answer.',
|
|
'answers.*.string' => 'Each answer must be a valid text value.',
|
|
'answers.*.in' => 'Each answer must be either "yes" or "no".',
|
|
];
|
|
}
|
|
}
|