abstractrs / laravel-filters
Create filters which transform input values, by removing or changing characters within the value.
v2.09
2020-03-02 14:52 UTC
Requires
- illuminate/console: ~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.2.0
- illuminate/support: ~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.2.0
- symfony/console: ^4.1|^4.3.5
README
This package allows you to easily create / use filters which transform input values, by removing or changing characters within the value.
Installation
composer require abstractrs/laravel-filters
Laravel will discover the package by itself. If you feel old-school, disable auto-discovery and add Abstractrs\Form\Request\RequestFilterProvider::class
to the providers array in your config/app.php.
Config - publish vendor
php artisan vendor:publish --tag=laravel-filters
config/filters.php
<?php return [ 'aliases' => [ 'encrypt' => \Abstractrs\Form\Request\Filters\EncryptFilter::class, 'decrypt' => \Abstractrs\Form\Request\Filters\DecryptFilter::class, 'hash' => \Abstractrs\Form\Request\Filters\HashFilter::class, 'lower' => \Abstractrs\Form\Request\Filters\StringToLowerFilter::class, 'upper' => \Abstractrs\Form\Request\Filters\StringToUpperFilter::class, 'null' => \Abstractrs\Form\Request\Filters\ToNullFilter::class, 'int' => \Abstractrs\Form\Request\Filters\ToIntFilter::class, ], 'namespace' => 'Http\\Filters' ];
Create custom filter
php artisan make:filter RemoveCharsFilter
Usage
<?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class LoginRequest extends FormRequest { //Filter public function filters() { return [ 'name' => 'lower|hash', 'names' => 'array:lower', // Call lower filter for each array value 'id' => 'int', 'date' => 'carbon,d/m/Y', 'created_date' => 'carbon' //default format -> filters.date_format (Y-m-d H:i:s) ]; } //... }