Possible to validate array of objects?
See original GitHub issueSay I’ve got an array of rooms, each room requires a room-number, nr of adults, nr of childs. It it currently possible to use dot-syntax to validate for rooms inside array?
req.checkBody(rooms.roomNumber).isEmpty()
doesn’t seem to work, which I understand because it probably checks for property roomNumber
on the array-object itself. Is there any way to do it instead?
I’m ok with iterating the separate rooms in a loop and checking, but I can’t use req.checkBody
for that I belive. I’d need something like validator.checkParam(room)
.
Any suggestions?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Laravel validate array of objects - Stack Overflow
You can use array validation of Laravel. eg. $validator = Validator::make($request->all(), [ 'row.*.title' => 'required', 'row.
Read more >Validating an array of objects - Laracasts
Validating an array of objects. Hello,. I'm making a REST endpoint which sends email, and for each recipient there needs to be both...
Read more >Validating an object or array of similarly-shaped objects with ...
It is a common requirement for a single API endpoint to accept both a single object and an array of similarly shaped objects....
Read more >How to Validate an Array of Objects in Laravel - Black Deer Dev
To validate an array of objects in Laravel, you can use the * identifier for each item in an array, and use the...
Read more >Nested Objects and Arrays - VeeValidate
Similar to objects, you can also nest your values in an array, using square brackets just like how you would do it in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could combine a custom validator with validator.js.
You could probably improve on this to add an array version for each method programmatically.
Hi! I had a similar problem writing a generic validator for all routes. This seems to be working so far, but please let me know if I’m leaving a gaping hole somewhere: