PHPackages                             peeyush-budhia/sanitizer - 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. peeyush-budhia/sanitizer

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

peeyush-budhia/sanitizer
========================

Sanitization library for PHP and the Laravel framework.

v1.5(3y ago)014MITPHPPHP ^8.0

Since Apr 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/peeyush-budhia/sanitizer)[ Packagist](https://packagist.org/packages/peeyush-budhia/sanitizer)[ Docs](https://github.com/peeyush-budhia/sanitizer)[ RSS](/packages/peeyush-budhia-sanitizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (4)Versions (7)Used By (0)

Laravel Sanitizer
=================

[](#laravel-sanitizer)

![PHP Version](https://camo.githubusercontent.com/7479bbea621500ec22a0369e3c27439c8aa452b173659fb63418115d5382d709/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706565797573682d6275646869612f73616e6974697a65723f636f6c6f723d626c7565267374796c653d666f722d7468652d6261646765)[![LICENSE](https://camo.githubusercontent.com/b966c1e4fe59b89fb9843bbdce6dab03ea03759361366dce149acb165531fdcc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706565797573682d6275646869612f73616e6974697a65723f636f6c6f723d626c7565267374796c653d666f722d7468652d6261646765)](https://github.com/peeyush-budhia/sanitizer/blob/master/LICENSE.md)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eacec87871e816516d6e0bf897f099622f40f1f2dad83cc488d22ad22d736854/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706565797573682d6275646869612f73616e6974697a65722e7376673f636f6c6f723d626c7565267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/peeyush-budhia/sanitizer)[![Total Downloads](https://camo.githubusercontent.com/b4ca92bba0f776ef7be75206c22daf6a6e467a826c0e81f05b09dc741947d79e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706565797573682d6275646869612f73616e6974697a65722e7376673f636f6c6f723d626c7565267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/peeyush-budhia/sanitizer)

[![Build Status](https://camo.githubusercontent.com/e22e7fb299f1d3d56ed7272b97aadc5460f774a599d65eb24572758ebc98332e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f706565797573682d6275646869612f73616e6974697a65723f7374796c653d666f722d7468652d6261646765)](https://travis-ci.com/peeyush-budhia/sanitizer)

Sanitization library for PHP and the Laravel framework.

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

[](#installation)

You can install the package via composer:

```
composer require peeyush-budhia/sanitizer
```

Core PHP Usage
--------------

[](#core-php-usage)

```
use Peeyush\Sanitizer\Sanitizer;

$data = [
    'name' => ' peeyush ',
    'birth_date' => '1987-09-10',
    'email' => 'Peeyush.Budhia@Gmail.CoM',
    'phone' => '(000)-000-00-00',
    'json' => '{"name":"Peeyush"}',
];

$filters = [
    'name' => 'trim|capitalize',
    'birth_date' => 'trim|format_date:"Y-m-d","F j, Y"',
    'email' => ['trim', 'lowercase'],
    'phone' => 'digit'
    'json' => 'cast:array',
];

$sanitizer = new Sanitizer($data, $filters);

var_dump($sanitizer);
```

Will return:

```
[
    'name' => 'Peeyush',
    'birth_date' => 'September 10, 1987',
    'email' => 'peeyush.budhia@gmail.com',
    'phone' => '0000000000'
    'json' => ['name' => 'Peeyush'],
];
```

Laravel Usage
-------------

[](#laravel-usage)

- Register the `provider` and update the `alias` of Sanitizer in `config/app.php` as under:

```
'providers' => [
        /*
         * Package Service Providers...
         */
        \Peeyush\Sanitizer\SanitizerServiceProvider::class,
    ]
```

```
'aliases' => [
        /*
         * Package aliases...
         */
        'Sanitizer' => \Peeyush\Sanitizer\Facade\SanitizerFacade::class,
    ],
```

- Now Publish `request.stub` and `tests` directory. To publish, run the following command on terminal, in the document root of the application:

```
php artisan vendor:publish --provider="Peeyush\Sanitizer\SanitizerServiceProvider"
```

###### After the above process you can use Sanitizer as follows

[](#after-the-above-process-you-can-use-sanitizer-as-follows)

- Use the Sanitizer through the Facade:

```
$data = Sanitizer::make($data, $filters)->sanitize();
```

- Use SanitizeInput trait to Sanitize input in your FormRequests. Please note you need to add filters method which returns the filters you want to apply to the input.

```
namespace App\Http\Requests;

use Peeyush\Sanitizer\SanitizeInput;

class ExampleRequest extends Request
{
    use SanitizeInput;

    public function filters()
    {
        return [
            'name' => 'trim|capitalize',
        ];
    }
}
```

- To auto generate the Request file run the following command on terminal, in the document root of the application:

```
php artisan make:Request ExampleRequest
```

Available Filters
-----------------

[](#available-filters)

FilterDescription`trim`Trims a string`escape`Escapes HTML and other special characters`lowercase`Converts a string to lowercase`uppercase`Converts a string to UPPERCASE`capitalize`Converts a string to Title Case`cast`Casts a variable into the given type. Options are: `int`, `float`, `string`, `bool`, `object`, `array` and Laravel Collection `collection``format_date`Converts the date format. It takes two arguments, `first` date's given format `second` date's target format`strip_tags`Strip HTML and PHP tags`digit`Get only digit characters from a stringCustom Filters
--------------

[](#custom-filters)

- Use Closure or Class that implements `Peeyush\Sanitizer\Contracts\Filter` interface:

```
class RemoveStringFilter implements \Peeyush\Sanitizer\Contracts\Filter
{
    public function apply($value, array $options)
    {
        return str_replace($options, '', $value);
    }
}

$filters = [
    'remove_strings' => RemoveStringsFilter::class,
];

$sanitize = new Sanitizer($data, $filters)
```

Credits
-------

[](#credits)

- [Peeyush Budhia](https://github.com/peeyush-budhia)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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

Every ~136 days

Recently: every ~170 days

Total

6

Last Release

1181d ago

PHP version history (3 changes)v1.0PHP ^7.4

v1.3PHP ^7.3|^7.4

v1.4PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9dd15157ed2d2b97842ef85e578d7a216cfa73e5da9e59f0668aaff9668577ec?d=identicon)[peeyush.budhia](/maintainers/peeyush.budhia)

---

Top Contributors

[![peeyush-budhia](https://avatars.githubusercontent.com/u/9695639?v=4)](https://github.com/peeyush-budhia "peeyush-budhia (16 commits)")

---

Tags

filterslaravelphpsanitizerphplaravelsanitizerfiltersanitizationinput filterinput sanitizerinput-sanitizationdata filterdata sanitizationpeeyush-budhiadata sanitizer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/peeyush-budhia-sanitizer/health.svg)

```
[![Health](https://phpackages.com/badges/peeyush-budhia-sanitizer/health.svg)](https://phpackages.com/packages/peeyush-budhia-sanitizer)
```

###  Alternatives

[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

115950.4k2](/packages/elegantweb-sanitizer)[kalfheim/sanitizer

Data sanitizer for PHP with built-in Laravel support.

1423.7k](/packages/kalfheim-sanitizer)

PHPackages © 2026

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