Is it possible to get the failing elements from the input array (or indexes at least)?
Example:
$data = [
['name' => 'John', 'age' => 30],
['name' => 'Robert', 'age' => 'nope'],
['name' => ['woops'], 'age' => 10]
];
$validator = \Validator::make($data, [
'*.name' => 'required|string|max:200',
'*.age' => 'required|int'
]);
if(!$validator->passes()){
/*
Get all the failed elements.
In this case:
[
['name' => 'Robert', 'age' => 'nope'],
['name' => ['woops'], 'age' => 10]
]
*/
$fails = $validator->getFailElements();
// OR
/*
Get failed indexes:
[1,2]
*/
$indexes = $validator->getFailIndexes();
//Proceed...
}
The reason is that I'd like to insert invalid data in a table, so it is possible to fix those entries later...
You can call invalid() on the validator to get the failed data.
$failed = $validator->invalid();

Reference: https://github.com/illuminate/validation/blob/master/Validator.php#L544
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With