Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikunj001's avatar

How to code for validating multiple data with similar parameter in compact way for Laravel API?

These are my API parameters

"feed_back":[
        {
            "feedId": "1",
            "rating": "1",
            "answer": "nice"
        },
        {
            "feedId": "2",
            "rating": "2",
            "answer": "nice"
        },
        {
            "feedId": "3",
            "rating": "3",
            "answer": ""
        }
    ]

For example, if I am having one of the parameters missing in the third response. so how to provide validation in this type of parameter. I can do the validation using for loop. But, I am looking for a more compact way for this type of validation.

0 likes
2 replies
aurawindsurfing's avatar

Hey @nikunj001

The only ok way I saw to do this was to decode json to array and then validate the data. There is no nice "laravel" way to do it straight away with json as far as I'm aware.

Please or to participate in this conversation.