Validation failed returns only first message in vuejs


Hi Guyzzz,
I want to get back all the failed messages when validation failed.But my code returns only the first message.Here is my code.


'use strict'

class AddUser {
  get rules() {
    // Unique Field Restriction for Editing
    const userId =
    const rules = {
      'newUserInfo.fname': 'required',
      'newUserInfo.lname': 'required',
      'newUserInfo.username': `required|unique:users,username,id,${userId}`,
      '': `required|email|unique:users,email,id,${userId}`,
      'newUserInfo.password': 'required|min:6'
    return rules
    // return {
    //   fname: 'required',
    //   lname: 'required',
    //   username: `required|unique:users,username,id,${userId}`,
    //   email: `required|email|unique:users,email,id,${userId}`,
    //   password: 'required|min:6'
    // }

   * Custom Validation Messages
  get messages() {
    return {
      'newUserInfo.fname.required': 'First name is missing',
      'newUserInfo.lname.required': 'Last name is missing',
      'newUserInfo.username.required': 'Username is missing',
      'newUserInfo.username.unique': 'Username name is already registered',
      '': 'Email is missing',
      '': 'Email is not valid',
      '': 'Email is already registered.',
      'newUserInfo.password.required': 'You must provide a password'

   * validation fails messages
  // async fails(errorMessages) {
  //return this.ctx.response.redirect('back')
  //return errorMessages
  // }

module.exports = AddUser

I am using vuejs as front end and sending the request using axios
My username and email fields are unique.But it only returns the username related message even though i have provided the same email
It should return two messages. Here is the response

Any help please.


Use validateAll option


Thanks boss @virk :slight_smile: