poppinss / indicative

Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
https://indicative.adonisjs.com/
MIT License
417 stars 52 forks source link

How can I add a Unique rule? #205

Closed rostamiani closed 6 years ago

rostamiani commented 6 years ago

I need Unique rule. How can I add it? Or how can I add it using adonis-validator?

Thanks for your perfect module

thetutlage commented 6 years ago

Read the Adonisjs docs, there’s already a unique rule

rostamiani commented 6 years ago

Thanks. But What do I import to use that rule in indicative? Is there any example?

thetutlage commented 6 years ago

I am not sure if you have read the docs https://adonisjs.com/docs/4.1/validator#_uniquetablename_fieldname_ignorefield_ignorevalue.

All indicative rules are preloaded in AdonisJs, since it's using the full build

rostamiani commented 6 years ago

Do I have to import Adonis validator to use unique rule? I'm confused. Should I do it like this? :

rules = { username: [ rule('unique:users') ] }

Or this:

rules = { username: "unique:users'" }

Thanks

thetutlage commented 6 years ago

Have you even read the AdonisJs docs? If yes, please share the link

rostamiani commented 6 years ago

I'm using indicative with my Express.js app. This is not an Adonis app then I cannot use Adonis CLI to install validator. Documentation instructions requires this: adonis install @adonisjs/validator

thetutlage commented 6 years ago

This is the information you should told at first. But anyways, you cannot use @adonisjs/validator with express, since it's written specifically for Adonis.

Also the unique rule relies on the database, so you have to add your own rule based upon the database you are using.

Here's the docs on extend method of indicative https://indicative.adonisjs.com/docs/api/extend

Mauricio-Arantes commented 4 years ago

that's my same question and unfortunately this link is no longer working, now, is this: https://indicative.adonisjs.com/validations/master/same

but, don't answer the question how to do a unique rule