Download the PHP package aporat/laravel-filter-var without Composer
On this page you can find all versions of the php package aporat/laravel-filter-var. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aporat/laravel-filter-var
More information about aporat/laravel-filter-var
Files in aporat/laravel-filter-var
Package laravel-filter-var
Short Description A Laravel package for filtering and sanitizing request variables with customizable rules
License MIT
Homepage https://github.com/aporat/laravel-filter-var
Informations about the package laravel-filter-var
Laravel Filter Var
A Laravel package for filtering and sanitizing request variables with a chainable, customizable filter system.
Features
- Chain multiple filters (e.g.,
trim,uppercase,cast) in a single call. - Built-in filters for common tasks (e.g.,
strip_tags,escape,format_date). - Support for custom filters via configuration.
- Seamless integration with Laravel's service container and facade system.
Requirements
- PHP: 8.4 or higher
- Laravel: 12.x or 13.x
- Composer: Required for installation
Installation
Install the package via Composer:
The service provider (FilterVarServiceProvider) is automatically registered via Laravel’s package discovery. If you’ve disabled auto-discovery, add it manually to config/app.php:
Optionally, register the facade for cleaner syntax:
Publish the configuration file to customize filters:
This copies config/filter-var.php to your Laravel config directory.
Usage
Basic Filtering
Filter and sanitize a request variable using the facade:
This:
- Casts the input to a string.
- Trims whitespace.
- Removes HTML/PHP tags.
- Escapes special HTML characters.
Available Filters
| Filter | Description | Example Input | Example Output |
|---|---|---|---|
capitalize |
Capitalizes words (title case) | hello world |
Hello World |
cast:<type> |
Casts to a type (e.g., int, string, bool, array, object, collection) |
123.45 (cast:int) |
123 |
digit |
Extracts digits only | abc123xyz |
123 |
escape |
Escapes HTML special characters | <p>Hello &</p> |
<p>Hello &</p> |
filter_if |
Conditional check on array key/value | ['key' => 'val'] |
true/false |
format_date |
Reformats a date string | 2023-01-15 |
15/01/2023 |
lowercase |
Converts to lowercase | HELLO |
hello |
normal_string |
Strips tags and keeps only Unicode letters and numbers (\p{L}, \p{N}), space, -:_. |
<b>Héllo</b> wörld! 123 |
Héllo wörld 123 |
remove_whitespace |
Removes all whitespace | a b c |
abc |
slugify |
Converts string into URL-friendly slug | Hello World! |
hello-world |
strip_tags |
Removes HTML/PHP tags | <b>Hello</b> |
Hello |
trim |
Trims whitespace | hello |
hello |
uppercase |
Converts to uppercase | hello |
HELLO |
cast:bool (or cast:boolean) understands boolean strings: 'true', '1', 'yes', 'on' become true and 'false', '0', 'no', 'off', '' become false (case-insensitive). Any other value uses PHP's native (bool) cast.
Chaining Filters
Chain multiple filters using the | separator:
Custom Filters
Add custom filters by editing config/filter-var.php:
Define the custom filter class:
Use it:
Using Without Facade
Resolve from the container:
Testing
Run the test suite:
Generate coverage reports for CI:
Contributing
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/amazing-feature). - Commit your changes (
git commit -m "Add amazing feature"). - Push to the branch (
git push origin feature/amazing-feature). - Open a pull request.
See CONTRIBUTING.md for details.
License
This package is open-sourced under the License File for more information.
Support
- Issues: GitHub Issues
- Source: GitHub Repository
All versions of laravel-filter-var with dependencies
ext-iconv Version *
ext-json Version *
ext-mbstring Version *
illuminate/support Version ^12.0 || ^13.0
illuminate/validation Version ^12.0 || ^13.0
nesbot/carbon Version ^3.0