Make sure to register the provider inside start/app.js
file.
const providers = [
'@adonisjs/validator/providers/ValidatorProvider'
]
That's all 🎉
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
class UserValidator {
get rules () {
// validation rules
}
get sanitizationRules () {
// sanitize data before validation
}
}
module.exports = UserValidator