Answer the question
In order to leave comments, you need to log in
Depending on the request, different form request validation conditions?
There is a validation done through a form request. The task is to change the validation parameters depending on the value of one of the parameters. The example below, everything works, but when there are several of these parameters, it turns out you need to repeat it.
I see a solution like this, create an empty array and fill it when the parameters match and return an associative array at the end. Is there a better solution?
if ($this->get('parametr') == 1) {
return [
'name' => 'required'
];
} else {
return [
'name' => 'required',
'age' => 'required'
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question