1

my request looks like this:

array:2 [
  "address" => array:1 [
    "data" => array:1 [
      "street" => ""
    ]
  ]
  "postal_address" => array:1 [
    "data" => array:1 [
      "street" => "random street"
    ]
  ]
]

And I want to validate that both streets are required, but I don't know how I can access it in my request I tried like this but It makes a new key and no validation:

public function rules()
{
    return [
        'address.data.street'  => 'required|max:16',
        'postal_address.data.street' => 'required|max:16',
    ];
}

It returns a weird formatted object:

errors: {
    address.data.street: [
      0: "required."
    ]
} 
1
  • you code works fine for me using the latest laravel version, it returns: "address.data.street": ["The address.data.street field is required."] Commented Apr 17, 2020 at 19:15

1 Answer 1

1

You may try the following

public function rules()
{
    return [
        'address' => 'array',
        'address.data' => 'array',
        'address.data.street' => 'required|max:16',
        'postal_address' => 'array',
        'postal_address.data' => 'array',
        'postal_address.data.street' => 'required|max:16'
    ];
}
Sign up to request clarification or add additional context in comments.

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.