My controller receives the following XHR request:
[
"data" => [
"key1" => "value1",
"key2" => "value2",
]
]
That’s why the validation always returns a fail. But I only want to validate the data within data. Is there a request validation function where I only pass the data?
2
Answers
I assume your controller receives data i.e.
As a user mentioned in the comments, you have to iterate each entry by using
data.KEY
format.If your data is like:
You can validate it like this:
Those rules are just examples, so please, do read How to validate arrays as the documentation has a defined section about it.
As Tim Lewis correctly mentioned, if all the keys have the same rules, then you can use one single rule and use
data.*
: