Core: adonis4 route validation

Created on 15 Sep 2017  路  7Comments  路  Source: adonisjs/core

I want to use validation method on resources

  .post('users', 'UserController.store')
  .validator('StoreUser')

something like this

Route.resource('users', 'UserController')
.validator('StoreUser')

on store method, is it possible to add this feature in future ?

Most helpful comment

Added in https://github.com/adonisjs/adonis-validation-provider/commit/d58e57c5e85c97491d2f3c4b4d2d696f4e603091

The syntax is as follows

Route
  .resource('users', 'UserController')
  .validator(new Map([
    ['users.store', 'StoreUser'],
    ['users.update', 'UpdateUser']
  ]))

All 7 comments

But how do u which method will be validated by adding validator on the resource?

only on post or put

But

  1. What if your validation rules are different for post and put?
  2. How to find which rules are for post and which are for put?

I think that its very common that for some resource you need validation rules, so if you have such cool validation method validate and you cant use it on resources then you must choose to use validation inside controller or not to use resource and describe every route separatly, is it possible to extend this method for something like this and to use it on Route.resource() ?

.validate({
 store: 'StoreUser',
 update: 'UpdateUser'
})

This syntax makes sense, will add support for it

Added in https://github.com/adonisjs/adonis-validation-provider/commit/d58e57c5e85c97491d2f3c4b4d2d696f4e603091

The syntax is as follows

Route
  .resource('users', 'UserController')
  .validator(new Map([
    ['users.store', 'StoreUser'],
    ['users.update', 'UpdateUser']
  ]))

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imperez picture imperez  路  4Comments

GianCastle picture GianCastle  路  3Comments

navdeepsingh picture navdeepsingh  路  3Comments

amrayoub picture amrayoub  路  4Comments

krunaldodiya picture krunaldodiya  路  3Comments