In my laravel (5.7) app I have a form request with an array of input fields. The Array "answers" has 8 distinct input fields. Until now I've been able to have a validation rule that checks each of the elements are at least 10 characters long.
class MyFormRequest extends FormRequest
{
public function rules()
{
$rules = [
'answers' =>'required',
'answers.*' =>'required|min:10',
];
}
}
but I want to change the requirement to only apply to 4 of the input fields, regardless of order. So if for example the user filled input fields number 1,5,6,8, each with 10 characters, the form would be accepted although fields 2,3,4,7 are empty. How can I achieve this? I read in the documentation that one can use the sometimes rule, but the examples use it in the controller and I don't undertand how I apply a custom sometimes rule in the FormRequest class.
Thanks in advance!