Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 697 Bytes

instructions.md

File metadata and controls

46 lines (31 loc) · 697 Bytes

Register provider

Make sure to register the provider inside start/app.js file.

const providers = [
  '@adonisjs/validator/providers/ValidatorProvider'
]

That's all 🎉

Route validator

This provider enables to write bind validators to the route.

Route
  .post('users', 'UserController.store')
  .validator('User')

Next create the validator file inside app/Validators directory, or use the ace command.

adonis make:validator User

app/Validators/User.js

class UserValidator {
 
  get rules () {
    // validation rules
  }

  get sanitizationRules () {
    // sanitize data before validation
  }

}

module.exports = UserValidator