0

I am sending following json array to server,

 {
    "details": {
        "0": {
            "name": "agency name"
        },
        "1": {
            "name": "agency name arabic"
        }
    }
}

I want to validate details in form request.

I tried as follows but not working fine,

protected $rules = [
        'details.*.name' => 'required|string',
    ];
1
  • What data set failed to validate? The one in your question is acceptable by the rules you've specified. Commented Apr 18, 2016 at 18:37

2 Answers 2

1

The problem here is that you don't send array here, you should send it like this:

{
    "details": [
        {
            "name": "agency name"
        },
        {
            "name": "agency name arabic"
        }
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

0

I send below array from a HTML+Vue.js data grid/table:

[0] => Array
    (
        [item_id] => 1
        [item_no] => 3123
        [size] => 3e
    )
[1] => Array
    (
        [item_id] => 2
        [item_no] => 7688
        [size] => 5b
    )

And use this to validate:

$this->validate($request, [ '*.item_id' => 'required|integer', '*.item_no' => 'required|integer', '*.size' => 'required|max:191', ]);

Comments

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.