PHPackages                             aporat/laravel-filter-var - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. aporat/laravel-filter-var

ActiveLibrary[Search &amp; Filtering](/categories/search)

aporat/laravel-filter-var
=========================

A Laravel package for filtering and sanitizing request variables with customizable rules

v5.0.0(1mo ago)21.6k↑100%1MITPHPPHP ^8.4CI passing

Since Aug 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/aporat/laravel-filter-var)[ Packagist](https://packagist.org/packages/aporat/laravel-filter-var)[ Docs](https://github.com/aporat/laravel-filter-var)[ GitHub Sponsors](https://github.com/sponsors/aporat)[ RSS](/packages/aporat-laravel-filter-var/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (9)Used By (1)

Laravel Filter Var
==================

[](#laravel-filter-var)

[![Latest Stable Version](https://camo.githubusercontent.com/9c210927a609d36ce6e87ae7026acc8bc00a0387eab9a82153279917f3533072/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61706f7261742f6c61726176656c2d66696c7465722d7661722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/aporat/laravel-filter-var)[![Downloads](https://camo.githubusercontent.com/3644f674db417a905f12f7fa79ef58b4b7cb5c047f0c8af8d55f9c18fc40b973/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61706f7261742f6c61726176656c2d66696c7465722d7661722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/aporat/laravel-filter-var)[![Codecov](https://camo.githubusercontent.com/da291d2208d3cfc41c5585285734c333e1f99f6ceddce65b0ff98b9916f33064/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f61706f7261742f6c61726176656c2d66696c7465722d7661723f7374796c653d666c61742d737175617265)](https://codecov.io/github/aporat/laravel-filter-var)[![Laravel Version](https://camo.githubusercontent.com/2de24cdf889694b542b8b1347fa6bb55ad1e52392a3105c9596e318064a6f8b0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e7825323025374325323031332e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/docs/13.x)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/7922bca9e0422f5088afdfeea6db1510ee7d75e616bfa78a6ffa9b61971366a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61706f7261742f6c61726176656c2d66696c7465722d7661722f63692e796d6c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7922bca9e0422f5088afdfeea6db1510ee7d75e616bfa78a6ffa9b61971366a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61706f7261742f6c61726176656c2d66696c7465722d7661722f63692e796d6c3f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/dd045322c2d784b36e1311fdd7014f1d20cdee3fc60c43d421ad0df726e0ff5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61706f7261742f6c61726176656c2d66696c7465722d7661722e7376673f7374796c653d666c61742d737175617265)](https://github.com/aporat/laravel-filter-var/blob/master/LICENSE)

A Laravel package for filtering and sanitizing request variables with a chainable, customizable filter system.

Features
--------

[](#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
------------

[](#requirements)

- **PHP**: 8.4 or higher
- **Laravel**: 12.x or 13.x
- **Composer**: Required for installation

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org/):

```
composer require aporat/laravel-filter-var
```

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`:

```
'providers' => [
    // ...
    \Aporat\FilterVar\FilterVarServiceProvider::class,
],
```

Optionally, register the facade for cleaner syntax:

```
'aliases' => [
    // ...
    'FilterVar' => Aporat\FilterVar\Facades\FilterVar::class,
],
```

Publish the configuration file to customize filters:

```
php artisan vendor:publish --provider="Aporat\FilterVar\FilterVarServiceProvider" --tag="config"
```

This copies `config/filter-var.php` to your Laravel config directory.

Usage
-----

[](#usage)

### Basic Filtering

[](#basic-filtering)

Filter and sanitize a request variable using the facade:

```
use Aporat\FilterVar\Facades\FilterVar;

$userAgent = FilterVar::filterValue('cast:string|trim|strip_tags|escape', $request->header('User-Agent'));
```

This:

- Casts the input to a string.
- Trims whitespace.
- Removes HTML/PHP tags.
- Escapes special HTML characters.

### Available Filters

[](#available-filters)

FilterDescriptionExample InputExample Output`capitalize`Capitalizes words (title case)`hello world``Hello World``cast:`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`Hello &``&lt;p&gt;Hello &amp;&lt;/p&gt;``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 `A-Z`, `0-9`, space, `-:_.``alert(1)``alert1``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`Hello``Hello``trim`Trims whitespace` hello ``hello``uppercase`Converts to uppercase`hello``HELLO`### Chaining Filters

[](#chaining-filters)

Chain multiple filters using the `|` separator:

```
$result = FilterVar::filterValue('trim|uppercase|cast:string', '  hello world  ');
// Returns: "HELLO WORLD"
```

### Custom Filters

[](#custom-filters)

Add custom filters by editing `config/filter-var.php`:

```
return [
    'custom_filters' => [
        'media_real_id' => \App\Filters\MediaRealId::class,
    ],
];
```

Define the custom filter class:

```
namespace App\Filters;

use Aporat\FilterVar\Contracts\Filter;

class MediaRealId implements Filter
{
    public function apply(mixed $value, array $options = []): string
    {
        $value = (string) $value;
        return str_contains($value, '_') ? explode('_', $value, 2)[0] : $value;
    }
}
```

Use it:

```
$result = FilterVar::filterValue('media_real_id', '11111_22222');
// Returns: "11111"
```

### Using Without Facade

[](#using-without-facade)

Resolve from the container:

```
$result = app('filter-var')->filterValue('trim', '  hello  ');
// Returns: "hello"
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Generate coverage reports for CI:

```
composer test-ci
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please:

1. Fork the repository.
2. Create a feature branch (`git checkout -b feature/amazing-feature`).
3. Commit your changes (`git commit -m "Add amazing feature"`).
4. Push to the branch (`git push origin feature/amazing-feature`).
5. Open a pull request.

See [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

This package is open-sourced under the [MIT License](LICENSE). See the [License File](LICENSE) for more information.

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/aporat/laravel-filter-var/issues)
- **Source**: [GitHub Repository](https://github.com/aporat/laravel-filter-var)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance89

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 81.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~339 days

Recently: every ~101 days

Total

7

Last Release

56d ago

Major Versions

v1.0.0 → v2.0.02024-11-25

v2.0.0 → v3.0.02025-02-05

3.1.2 → v4.0.02025-09-18

v4.0.0 → v5.0.02026-03-18

PHP version history (4 changes)v1.0.0PHP ^7.2.5

v2.0.0PHP ^8.2

v3.1.0PHP ^8.3

3.1.2PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/54592564aa6e76cb00fdb16a8b7fadaea333de11da7fd8a739fe4812237a551c?d=identicon)[aporat](/maintainers/aporat)

---

Top Contributors

[![aporat](https://avatars.githubusercontent.com/u/415576?v=4)](https://github.com/aporat "aporat (77 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (5 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (3 commits)")

---

Tags

requestlaravelvalidationfiltersanitizedata processingfilter-var

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aporat-laravel-filter-var/health.svg)

```
[![Health](https://phpackages.com/badges/aporat-laravel-filter-var/health.svg)](https://phpackages.com/packages/aporat-laravel-filter-var)
```

###  Alternatives

[aura/filter

Filters to validate and sanitize objects and arrays.

173561.0k10](/packages/aura-filter)[kyslik/laravel-filterable

Using URL query strings to filter Eloquent queries.

11539.0k](/packages/kyslik-laravel-filterable)[stolz/laravel-html-tidy

HTML Tidy middleware for Laravel

278.7k](/packages/stolz-laravel-html-tidy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
