Feature Request: Get subset of request data filtered by validation rules
See original GitHub issueHello!
Thank you for this great module. However, I’m looking for a way to get a subset of request data filtered by validation rules.
I will give a small example:
/** Imagine that this is the request body.
{
firstName: 'Slava',
lastName: 'Fomin',
email: 's.fomin@betsol.ru',
password: 'some-pass-here',
someExtra: 'foo'
}
*/
// I'm using this map to specify validation rules for the request.
req.checkBody({
firstName: {},
lastName: {},
email: {
notEmpty: {
errorMessage: 'Missing E-Mail'
},
isEmail: {
errorMessage: 'Incorrect E-Mail address'
}
}
});
var errors = req.validationErrors(true);
if (errors) {
return res.json(400, {
errors: errors
});
}
var requestParams = req.getValidatedBody();
// We are getting only parameters specified during the validation phase,
// the extra request parameters, like "password", are ignored.
console.log(requestParams);
/**
{
firstName: 'Slava',
lastName: 'Fomin',
email: 's.fomin@betsol.ru'
}
*/
That way I will be able to use the entire object without the fear of overwriting some protected property later on (e.g. when updating user entity).
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
The Smart Way To Handle Request Validation In Laravel
Laravel has Form Request, A separate request class containing validation logic. To create one you can use below Artisan command. Laravel Form ......
Read more >Configure Request Filtering in IIS - Microsoft Learn
Open IIS Manager and select the level for which you want to configure request filter. In Features View, double-click Request Filtering.
Read more >Validation - Laravel - The PHP Framework For Web Artisans
Each form request generated by Laravel has two methods: authorize and rules . * Get the validation rules that apply to the request....
Read more >Filtering and retrieving data using Amazon S3 Select
With Amazon S3 Select, you can use simple structured query language (SQL) statements to filter the contents of an Amazon S3 object and...
Read more >Use conditions in Realtime Database Security Rules - Firebase
If your app uses Firebase Authentication, the request.auth variable contains the ... the format and content of data should be done using .validate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello folks! v4.0.0 has finally been released!
You can now get the subset of data matched by any validations by using the new APIs
check
andfilter
:Please check the README for complete docs, and also check the upgrade guide.
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.