Exists is not defined as a validation AdonisJs 4.0

#1

Route
.post(’/save/address’, ‘AddressController.newFavoriteAddress’)
.validator(‘SaveAddressUser’);

create class SaveAddressUser

'use strict'
const BaseValidators =use('App/Validators/BaseValidators')
class SaveAddressUser extends BaseValidators{

  get rules () {
    // const api = this.ctx.params.api
    return {
      api: 'required|min:40|max:40|exists:users,api',
      title:'required|min:3|max:255',
      lat: 'required|max:255',
      lng:'required|max:255',
      address: 'string|min:3|max:255'
    }
  }
  async fails (errorMessages) {

    return this.errors(2,errorMessages[0].message);
  }
}

module.exports = SaveAddressUser

then error Messages is exists is not defined as a validation

0 Likes

#2

Yes there is no inbuilt rule called exists. You’ll have to extend the validator to add one

0 Likes