validation
validation copied to clipboard
getValidatedData returns unknown keys
Hi
I have this rule set:
'id' => 'required|integer|unique:accounts,id|min:1',
'company' => 'required|max:255',
'domains' => 'required|array',
'domains.*.domain' => 'required|regex:/\A[\w:.-]+\z/|unique:domains,domain',
'domains.*.sslify' => 'bool|default:1',
'domains.*.redirect' => 'bool|default:0',
'domains.*.redirect_code' => 'in:301,302|default:301',
'domains.*.origin' => 'required|url',
And this query:
{
"id": 1,
"company": "asd",
"domains": [
{
"domain": "www.example.com",
"ssl": "true",
"origin": "https://www.google.com"
}
]
}
Mind the "ssl" key. It was not described in rules.
Still, I get it from getValidatedData()
call:
Array
(
[id] => 1
[company] => asd
[domains] => Array
(
[0] => Array
(
[domain] => www.example.com
[ssl] => true
[origin] => https://www.google.com
[sslify] => 1
[redirect] => 0
[redirect_code] => 301
)
)
)
Version is 1.1.1, PHP 7.3.3.
P. S. Same happens with getValidData().
The reason for this is 'domains' => 'required|array'
.
The reason why your ssl
key is present, is because the domains
array which holds it has been validated, all of its nested arrays have technically passed this rule.
This is a difficult one, because in this situation you would not expect to see ssl
in the validated data, but consider if you were only running the 'domains' => 'required|array'
rule; what would you expect back then?
I imagine it would be the populated domains
array, and not an empty version - 'domains' => []
.
This probably needs more discussion, but I consider it a quirk, and not a bug.