Indicative: I'm getting error in required rule when i do a PUT

I’m trying to implement validator in a put request, but i’m receiving error that my required rule is not being filled, but when i do a console.log() before i call the validate() method.

The same rules worsk well in post request.

What i tried:

const messages = {
 required: field => `${field} é obrigatório e não foi preenchido!`
}
const rules = (idIgnorar) => ({
 name: 'string|required'
})
async update ({ request, response }) {

    const estudante = await Estudante.findOrFail(request.params.id)

    estudante.merge({

      ...request.all(),

      user_id: request.user_id

    })

    const idIgnorar = ',id,'+estudante.id

    console.log(estudante.name) //is printing a value

    const validation = await validate(estudante, rules(idIgnorar), messages)

    if (validation.fails()) {

      return response.validateError(validation)

    }

So, in the console.log() is printing a name, but i’m receiving:

name é obrigatório e não foi preenchido!

I’m forgetting something? The same code works when i put in the post method store()

2 Likes

fixed using .toJSON():

const validation = await validate(estudante.toJSON(), rules(idIgnorar), messages)

2 Likes