PHPackages                             guerrilla/laravel-request-filters - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. guerrilla/laravel-request-filters

ActiveLibrary[HTTP &amp; Networking](/categories/http)

guerrilla/laravel-request-filters
=================================

Simple &amp; lean request filtering for Laravel 5.6+

1.0(5y ago)69062MITPHPPHP ^7.0 || ^8.0

Since Sep 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/guerrillacontra/laravel-request-filters)[ Packagist](https://packagist.org/packages/guerrilla/laravel-request-filters)[ Docs](https://github.com/guerrillacontra/laravel-request-filters)[ RSS](/packages/guerrilla-laravel-request-filters/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (2)Used By (0)

Laravel request filters
=======================

[](#laravel-request-filters)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Version on Packagist](https://camo.githubusercontent.com/c39e9093b5d0c38545ebe74078eab9e6060414276bbf82381b81ba25a8a6df70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6775657272696c6c612f6c61726176656c2d726571756573742d66696c746572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/guerrilla/laravel-request-filters)[![Total Downloads](https://camo.githubusercontent.com/da5c066185e66b3247a1205c1fd2f9f956dcca034be73f04bb777885da498785/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6775657272696c6c612f6c61726176656c2d726571756573742d66696c746572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/guerrilla/laravel-request-filters)

About
-----

[](#about)

Laravel provides tools to validate HTTP requests allowing developers to ensure the input data is in the correct structure.

This package provides tools to filter the valid data into the format intended.

It feels like it is part of the Laravel framework and couldn't be any simpler to use.

Requirements
------------

[](#requirements)

Laravel 5.6+

Features
--------

[](#features)

- Format input with a collection of pre-made and tested Filters
- `FilterRequests` trait that easily plugs into a `FormRequest` and enable filtering
- `InputFilter` that allows developers to easily implement their own filters
- `RequestFiltering` tool that can apply the same filters to any string you pass in
- [Nested AND array filtering just like Laravel's own validator 👌](https://laravel.com/docs/7.x/validation#validating-arrays)
- String based filtering similar to Laravel's validator + custom parsable filters

Included Filters
----------------

[](#included-filters)

Filter classUsageFilterCapitalizeCapitalizes the first character of each wordFilterSanitizeEscapes characters based on php's own validator constantsFilterSanitizeEmailSanitizes emailFilterSanitizeTextSanitizes text genericallyFilterSanitizeEncodedURL Encodes textFilterNumericRemoves all non-numerical charactersFilterStripTagRemoves HTML and PHP tags, keeps what you wantFilterToLowerConverts to lowercaseFilterToUpperConverts to uppercaseFilterTrimTrim leading and trailing white spaceFilterDateFormat into a specified Carbon date string see [Carbon docs](https://carbon.nesbot.com/docs/#api-formatting)Included Filters (as string literals)
-------------------------------------

[](#included-filters-as-string-literals)

Filter classUsage'capitalize'Capitalizes the first character of each word'email'Sanitizes email'sanitize'Sanitizes text generically'encode'URL Encodes text'number'Removes all non-numerical characters'strip'Removes HTML and PHP tags, keeps what you want'lowercase'Converts to lowercase'uppercase'Converts to uppercase'trim'Trim leading and trailing white space'date'Format into a specified Carbon date string see [Carbon docs](https://carbon.nesbot.com/docs/#api-formatting)You can make your own custom filters by implementing the `FilterInterface` :)

How to use
----------

[](#how-to-use)

Import via composer:

`composer require guerrilla/laravel-request-filters`

In your [FormRequest](https://laravel.com/docs/7.x/validation#form-request-validation) use the following trait:

`use Guerrilla\RequestFilters\FilterRequests`

Describe your filters (Laravel rules included for familiarisation):

```
public function rules():array {
    return [
        'email' => ['required', 'email', 'bail'],
        'name' => ['required'],
        'employees.*.name' =>['required']
    ];
}
```

```
public function filters():array {
    return [
        'email' => [new FilterTrim, new FilterSanitizeEmail],
        'name' => [new FilterTrim, new FilterSanitizeText, new FilterCapitalize],
        'employees.*.name' => [new FilterCapitalize],
        'date' => [new FilterTrim, new FilterDate('d/m/Y')]
    ];
}
```

Or use the string based syntax:

```
public function filters():array {
    return [
        'email' => 'trim|email',
        'name' => 'trim|sanitize|capitalize',
        'employees.*.name' => 'capitalize',
        'date' => 'trim|date:d/m/Y'
    ];
}
```

Validate the request as per normal but, the results will be now filtered :)

```
$input = $request->validated();
echo $input['email'];
//trimmed and sanitized email!
```

You can optionally just run the filter on any string you like outside of the request:

```
$validated_input = $request->validate([...]);

$filtered_result = InputFilter::filter(
                  $validated_input,
                  [
                  'email' => [new FilterTrim],
                  'name' => [new FilterTrim],
                  'meta.*.attributes' => [new MyCustom1Filter(1), new MyCustom2Filter(2)]
                  ]
);
```

Using your own custom filtering rules to the string parsing syntax is easy!

```
$validated_input = $request->validate([...]);

$custom_filters = [
    'custom1' => MyCustom1Filter::class,
    'custom2' => MyCustom2Filter::class
];

$filtered_result = InputFilter::filterFromString(
                  $validated_input,
                  [
                  'email' => 'trim',
                  'name' => 'trim',
                  'meta.*.attributes' => 'custom1:1|custom2:2'
                  ],
                  $custom_filters
);
```

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2065d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20097812?v=4)[jameswrightson](/maintainers/jameswrightson)[@jameswrightson](https://github.com/jameswrightson)

---

Top Contributors

[![guerrillacontra](https://avatars.githubusercontent.com/u/6704177?v=4)](https://github.com/guerrillacontra "guerrillacontra (16 commits)")

---

Tags

requestapilaravelrestutilitytraitfiltersanitizeformrequest

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/guerrilla-laravel-request-filters/health.svg)

```
[![Health](https://phpackages.com/badges/guerrilla-laravel-request-filters/health.svg)](https://phpackages.com/packages/guerrilla-laravel-request-filters)
```

###  Alternatives

[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

400509.0k3](/packages/pusher-pusher-http-laravel)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[illuminatech/data-provider

Allows easy build for DB queries from API requests

4413.3k](/packages/illuminatech-data-provider)

PHPackages © 2026

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