2

I make a post request to the Laravel server from the Vue.js server. How I can validate complex array in request on the server-side.

Here is my request payload:

{
    "insurance": [
        "Blue Cross Blue Shield",
        "United Behavioral Health",
        "Aetna Behavioral Health",
        "Tricare East","Medicare","Humana"
      ],
    "caqh": {
        "username":"myusername",
        "password":"my password"
     },
    "nppes": {
        "username":"new username",
        "password":"passowrd"
    }
}

I want to validate all the fields via $request->validate([ 'username'=>'required' ]) How would I achieve this?

1

1 Answer 1

4
$request->validate([
    'insurance' => 'required',
    'insurance.caqh' => 'required',
    'insurance.nppes' => 'required',
    'insurance.caqh.username' => 'required',
    'insurance.nppes.username' => 'required',
    ])
Sign up to request clarification or add additional context in comments.

2 Comments

The method is not working. I submitted all the values but it is still returning errors
Can you elaborate a little bit more ? You can dd($request->all()) and check the structure of data you are trying to validate and then compare it with validation rules

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.