Core: Route parameters regexp validation

Created on 27 Sep 2017  路  4Comments  路  Source: adonisjs/core

Is there a way to bind the route parameter to satisfy a specific regexp? For example, in Laravel, we can write Route::get('user/{id}')->where('id', '[0-9]+') to allow only numeric values as id.

I tried, in Adonis v4, to use .where('id', '[0-9]+') after the route but obviously it doesn't work.

Most helpful comment

There is no .where method, but you can define the regex inline.

Route.get('user/:id([0-9]+)', ({ params }) => params.id)

All 4 comments

There is no .where method, but you can define the regex inline.

Route.get('user/:id([0-9]+)', ({ params }) => params.id)

Oh, thank you! I have another question about the integration of eslint with adonis. The goal is to throw an error in the app (localhost:3333, not only on the console) if the lint fails. Before I open another issue, is that possible? At this time, with some edits on the package.json and the module npm-run-all I can check real-time the lint, but the errors appear only in the terminal.

Maybe you can ask this question on the forum. https://forum.adonisjs.com/

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

Extarys picture Extarys  路  4Comments

PC-HUB picture PC-HUB  路  4Comments

devcaststudio picture devcaststudio  路  3Comments

imperez picture imperez  路  4Comments

milosdakic picture milosdakic  路  3Comments