jeudi 10 octobre 2019

Is it possible to get elements of array that failed validation in laravel

I have an array I want to validate, each element has an id field and it could also contain nested arrays, so I want to get all errors and if it's possible get elements that didn't pass validation.

I've tried to get all messages from validator $validator->messages()->all() but it return only messages from lowest level of arrays.

So if i pass something like this:

$object = [
    'field1' => 'wont_pass_validation',
    'id' => 0,
    'nested_object' => [
        'field2' => 'wont_pass_validation_either',
        'id' => 1'
     ]
]

it will return only field2 message, without field1.
If there is a way to get all messages and is it possible to get failed elements so I could extract id fields from them?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire