Download the PHP package arondeparon/laravel-request-sanitizer without Composer
On this page you can find all versions of the php package arondeparon/laravel-request-sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arondeparon/laravel-request-sanitizer
More information about arondeparon/laravel-request-sanitizer
Files in arondeparon/laravel-request-sanitizer
Package laravel-request-sanitizer
Short Description An easy to use request sanitizer that allows you to sanitize your form data before validating it.
License MIT
Homepage https://github.com/arondeparon/laravel-request-sanitizer
Informations about the package laravel-request-sanitizer
Laravel Request Sanitizer
The arondeparon/laravel-request-sanitizer
package provides a fluent interface to sanitize form requests before validating them.
Why should I use this package?
Often, validating your request is not enough. The request sanitizer allows you to easily
manipulate your form data before passing it to the validator. You can start using it in a matter
of minutes and it is fully compatible with Laravel's FormRequest
object.
Table of Contents
- How to use
- Installing
- Usage
- Predefined Sanitizers
- FilterVars usage
- Writing your own Sanitizer
- Testing
- Credits
- License
How to use
Syntax is similar to the way rules
are added to a Form Request.
Installing
composer require arondeparon/laravel-request-sanitizer
Usage
- Add the
SanitizesInputs
trait to your form request. - Write your own sanitizers or use one of the supplied sanitizers and add them to the
$sanitizers
property of your form request. - Your request data will now be sanitized before being validated.
Predefined Sanitizers
Trim
- simple PHPtrim()
implementationTrimDuplicateSpaces
replaces duplicate spaces with a single space.RemoveNonNumeric
- removes any non numeric characterCapitalize
- capitalizes the first character of a stringUppercase
- converts a string to uppercaseLowercase
- converts a string to lowercaseFilterVars
- simple PHPfilter_var
sanitizerCarbonDate
- cast a string to a Carbon object- Contributions are appreciated!
FilterVars usage
The FilterVars sanitizer acts as a wrapper of the default PHP filter_var
function.
It accepts the same (optional) parameters as the original function.
Both parameters can be either an array
or string
type:
For more information on filter_vars please refer to https://www.php.net/manual/en/function.filter-var.php.
Writing your own Sanitizer
Writing your own sanitizer can be done by implementing the Sanitizer
interface, which requires only
one method.
Testing
$ composer test
Credits
- Aron Rotteveel
- All Contributors
License
The MIT License (MIT). Please see License File for more information.