Files
go-no-go/app/Http/Requests/Session/UpdateSessionRequest.php
2026-02-16 11:19:06 +01:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Session;
use Illuminate\Foundation\Http\FormRequest;
final class UpdateSessionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->route('session')->user_id === auth()->id();
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'answers' => ['sometimes', 'array'],
'answers.*.value' => ['nullable', 'string', 'in:yes,no,not_applicable'],
'answers.*.text_value' => ['nullable', 'string', 'max:10000'],
'additional_comments' => ['sometimes', 'nullable', 'string', 'max:10000'],
'complete' => ['sometimes', 'boolean'],
];
}
/**
* Custom validation messages.
*/
public function messages(): array
{
return [
'answers.array' => 'Answers must be a valid data structure.',
'answers.*.value.in' => 'Answer value must be yes, no, or not_applicable.',
'answers.*.text_value.string' => 'Answer text must be text.',
'answers.*.text_value.max' => 'Answer text cannot exceed 10000 characters.',
'additional_comments.string' => 'Additional comments must be text.',
'additional_comments.max' => 'Additional comments cannot exceed 10000 characters.',
'complete.boolean' => 'The complete flag must be true or false.',
];
}
}