Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating JSON array #173

Open
vmihaly2020 opened this issue Jun 17, 2020 · 0 comments
Open

Validating JSON array #173

vmihaly2020 opened this issue Jun 17, 2020 · 0 comments

Comments

@vmihaly2020
Copy link

I have this

 JSON::make('translation', [
                Text::make('language_id')
                    ->withMeta([
                        'value' => $lang->id,
                    ])
                    ->rules(
                        'required'
                 ) ,
                Text::make($lang->name, 'value')
                    ->withMeta([
                        'value' => ($langVal ? $langVal[$lang->id] : ''),
                    ])
                    ->rules(
                      'required'
                    )

            ], 'translation['.$i.']')

                ->flatten();

And I always get this response

{
   "message":"The given data was invalid.",
   "errors":{
      "name":[
         "validation.required"
      ],
      "translation[0].language_id":[
         "validation.required"
      ],
      "translation[0].value":[
         "validation.required"
      ],
      "translation[1].language_id":[
         "validation.required"
      ],
      "translation[1].value":[
         "validation.required"
      ]
   }
}

Payload:

{
   "name":null,
   "translation":[
      {
         "language_id":"2",
         "value":null
      },
      {
         "language_id":"1",
         "value":null
      }
   ],
   "viaResource":null,
   "viaResourceId":null,
   "viaRelationship":null,
   "editing":"true",
   "editMode":"create"
}

How to validate the JSON array field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant