0

I am sending a request to my laravel project like below:

{
    "group_name": "Demo",
    "desc": "demo",
    "option_type_id": ["7", "8"],
    "products": [{
            "product_id": 3,
            "product_option_id": ["10", "17"]
        },
        {
            "product_id": 4,
            "product_option_id": ["10", "17"]
        },
        /// more
    ]
}

I want To validate that each product_option_id array set must be unique.
Like in the above case, it needs to return an array.

{
    "group_name":"Demo",
    "desc":"demo",
    "option_type_id":["7","8"],
    "products":[{
            "product_id":3,
            "product_option_id": ["10","17"]
        },
        {
            "product_id":4,
            "product_option_id": ["10","17"] // error: duplicate entry
        }
    ]
}

An example of accepted data:

{
    "group_name": "Demo",
    "desc": "demo",
    "option_type_id": ["7", "8"],
    "products": [{
            "product_id": 3,
            "product_option_id": ["10", "17"]
        },
        {
            "product_id": 4,
            "product_option_id": ["10", "16"] // accepted 
        },
        {
            "product_id": 5,
            "product_option_id": ["10", "18"] // accepted 
        },
        {
            "product_id": 6,
            "product_option_id": ["1", "18"] // accepted 
        }

    ]
}

How can I validate this request in my laravel?
I am a beginner, so can anyone help me to solve this?

2
  • This looks like a duplicate of this question: stackoverflow.com/questions/52312972/… Commented May 18, 2021 at 7:54
  • @on3ss No i Just Want check with each array like .. the combination should not be repeated values can be reapeated Commented May 18, 2021 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.