Im currently working on a search request that has 1 mandatory filter and either one of two other filters mandatory.
Currently I'm working with:
public function rules(): array
{
return [
'period' => [
'required',
'numeric',
Rule::exists('periods', 'id'),
],
'lessonClass' => [
'required_without:students',
'numeric',
Rule::exists('lesson_classes', 'id'),
],
'students' => [
'required_without:lessonClass',
'array',
'min:1',
'max:50',
],
'students.*' => [
'numeric',
Rule::exists('students', 'id'),
],
];
}
Ofcourse it works like a charm, only downside is that it will give two error messages when either lessonClass or students is missing.
Is there a way to get this to only show one error message, something like: "Either lessonClass or students is required"