Package Data | |
---|---|
Maintainer Username: | gcphost |
Maintainer Contact: | gcphost@gmail.com (William) |
Package Create Date: | 2016-07-31 |
Package Last Update: | 2018-04-27 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 15:17:17 |
Package Statistics | |
---|---|
Total Downloads: | 17 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Filter items before your validate them with Laravel 5s Validator.
Values will be filtered based on the function you provide. If the parameter exists in the request it will also be replaced.
composer require askedio/laravel-validator-filter
Add the following to the providers array in config/app.php
:
Askedio\LaravelValidatorFilter\FilterServiceProvider::class
You can use any function that is callable and accepts the value as the parameter.
$validator = app('validator')->make([
'string' => 'Hello ' . PHP_EOL . ' World',
], [
'string' => 'filter:strip_tags,nl2br',
]);
$validator->passes();
dd($validator->getData());
You can use a function with parameters in line. ()
= []
& ,
= ;
.
$validator = app('validator')->make([
'string' => 'Hello <br> World<p></p>',
], [
'string' => 'filter:strip_tags[{$value}; "<br>"]',
]);
$validator->passes();
dd($validator->getData());
You can also define your own custom filter.
app('filter')->register('plusOne', function ($value) {
return $value+1;
});
$validator = app('validator')->make([
'int' => '<br>1',
], [
'int' => 'filter:strip_tags,plusOne',
]);
$validator->passes();
dd($validator->getData());