Answer the question
In order to leave comments, you need to log in
Laravel: Why doesn't the validator pass?
Good afternoon. I accept an array of the form:
$array = [
'data' = [
0 => [
'title' => 'Название',
'price' => 700,
'quantity' => 5
],
1 => [
'title' => 'Название 2',
'price' => 800,
'quantity' => 3
],
2 => [
'title' => 'Название 3',
'price' => 900,
'quantity' => 2
]
];
];
public function myFunction()
{
$input = Input::get('data');
$validator = Validator::make($input, [
'title' => 'required',
'price' => 'required|numeric',
'quantity' => 'required|numeric'
]);
if ($validator->passes()) {
// Сюда не попадает
} else {
// А вот сюда попадает
}
}
Answer the question
In order to leave comments, you need to log in
Your data is an array.
As far as I know, the validator does not bypass the array. I think you need to make a loop that goes around the array, and already in it to do the validation of a specific element.
Variant from Stackoverflow .
Another option:
Iterate the collection up to the first error, or through the whole - as you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question