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.3 or higher
- Laravel: 10.x, 11.x or 12.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 ) |
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 |
strip_tags |
Removes HTML/PHP tags | <b>Hello</b> |
Hello |
trim |
Trims whitespace | hello |
hello |
uppercase |
Converts to uppercase | hello |
HELLO |
validate_email |
Validates email format | [email protected] |
[email protected] |
validate_url |
Validates URL format | https://example.com |
https://example.com |
cast_to_boolean |
Casts input to boolean | true , false |
true , false |
sanitize_number_int |
Keeps only digits | abc123 |
123 |
sanitize_number_float |
Keeps digits and decimals | abc12.3xyz |
12.3 |
remove_whitespace |
Removes all whitespace | a b c |
abc |
slugify |
Converts string into URL-friendly slug | Hello World! |
hello-world |
normal_string |
Strips tags and keeps A-Z , 0-9 , space, -:_. |
<script>alert(1)</script> |
alert1 |
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:
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-json Version *
illuminate/support Version ^10.0 || ^11.0 || ^12.0
nesbot/carbon Version ^2.72 || ^3.0