I'm trying to do input array validation. For now I've got this:
$rules = [
'name' => 'required|array',
];
if(array_key_exists('name', $data) && is_array($data['name'])) {
foreach ($data['name'] as $key => $value) {
$rules['name.' . $key] = 'required|nullable|string|max:255';
}
}
$v = Validator::make($data, $rules);
This code works, but I want to ensure that keys is also correct. I can simply add some more checks inside foreach
loop, but this makes validator itself useless as it would be simpler to check everything manually.
Perfectly, I want to achieve something like this:
$v = Validator::make($data, [
'name' => 'required|array',
'name.[a-z]{2}' => 'required|nullable|string|max:255'
]);
Is it possible by Validator
or maybe by some extension of it?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2m3rE2s
via IFTTT
Aucun commentaire:
Enregistrer un commentaire