G
G
Greg Popov2019-12-03 01:10:30
Laravel
Greg Popov, 2019-12-03 01:10:30

What are the solutions for nested error response in Laravel FormRequest?

Background:
We validate the collection, json comes in response:

representatives.0.email: ["Поле representatives.0.email обязательно для заполнения."]
representatives.0.first_name: ["Поле representatives.0.first_name обязательно для заполнения."]
representatives.1.email: ["Поле representatives.1.email обязательно для заполнения."]
representatives.1.first_name: ["Поле representatives.1.first_name обязательно для заполнения."]

Question:
Is there a way to make the field names normal, and make the answer nested so that it looks like this:
representatives : [
    0: {
        email: 'текст'
    },
    1: {
        email: 'текст'
    },
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-12-03
@JhaoDa

Yes - you need to override the method that forms the response with errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question