PHPackages                             ttbooking/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. ttbooking/sanitizer

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

ttbooking/sanitizer
===================

Data sanitizer and Laravel 8 form requests with input sanitation.

1.0.22(1mo ago)0310MITPHP

Since Sep 25Pushed 1mo agoCompare

[ Source](https://github.com/ttbooking/Sanitizer)[ Packagist](https://packagist.org/packages/ttbooking/sanitizer)[ RSS](/packages/ttbooking-sanitizer/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (8)Versions (21)Used By (0)

WAAVI Sanitizer
===============

[](#waavi-sanitizer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d31531a89e7bac45e56fb386f5db68971de80a5a20a26361a618fd9f6e9dbb29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7474626f6f6b696e672f73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ttbooking/sanitizer)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/abc2d07ec0615fded4ac8203d8ff566de85809abca4097e6ceb04f1736a016d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7474626f6f6b696e672f73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ttbooking/sanitizer)

About WAAVI
-----------

[](#about-waavi)

WAAVI is a Spanish web development and product consulting agency, working with Startups and other online businesses since 2013. Need to get work done in Laravel or PHP? Contact us through [waavi.com](http://waavi.com/en/contactanos).

Introduction
------------

[](#introduction)

WAAVI Sanitizer provides an easy way to format user input, both through the provided filters or through custom ones that can easily be added to the sanitizer library.

Although not limited to Laravel 5 users, there are some extensions provided for this framework, like a way to easily Sanitize user input through a custom FormRequest and easier extensibility.

Example
-------

[](#example)

Given a data array with the following format:

```
    $data = [
        'first_name'    =>  'john',
        'last_name'     =>  'DOE',
        'email'         =>  '  JOHn@DoE.com',
        'birthdate'     =>  '06/25/1980',
        'jsonVar'       =>  '{"name":"value"}',
        'description'   =>  'Test paragraph. Other text',
        'phone'         =>  '+08(096)90-123-45q',
        'country'       =>  'GB',
        'postcode'      =>  'ab12 3de',
    ];
```

We can easily format it using our Sanitizer and the some of Sanitizer's default filters:

```
    use \Waavi\Sanitizer\Sanitizer;

    $filters = [
        'first_name'    =>  'trim|escape|capitalize',
        'last_name'     =>  'trim|escape|capitalize',
        'email'         =>  'trim|escape|lowercase',
        'birthdate'     =>  'trim|format_date:m/d/Y, Y-m-d',
        'jsonVar'       =>  'cast:array',
        'description'   =>  'strip_tags',
        'phone'         =>  'digit',
        'country'       =>  'trim|escape|capitalize',
        'postcode'      =>  'trim|escape|uppercase|filter_if:country,GB',
    ];

    $sanitizer  = new Sanitizer($data, $filters);
    var_dump($sanitizer->sanitize());
```

Which will yield:

```
    [
        'first_name'    =>  'John',
        'last_name'     =>  'Doe',
        'email'         =>  'john@doe.com',
        'birthdate'     =>  '1980-06-25',
        'jsonVar'       =>  '["name" => "value"]',
        'description'   =>  'Test paragraph. Other text',
        'phone'         =>  '080969012345',
        'country'       =>  'GB',
        'postcode'      =>  'AB12 3DE',
    ];
```

It's usage is very similar to Laravel's Validator module, for those who are already familiar with it, although Laravel is not required to use this library.

Filters are applied in the same order they're defined in the $filters array. For each attribute, filters are separered by | and options are specified by suffixing a comma separated list of arguments (see format\_date).

Available filters
-----------------

[](#available-filters)

The following filters are available out of the box:

FilterDescription**trim**Trims a string**escape**Escapes HTML and special chars using php's filter\_var**lowercase**Converts the given string to all lowercase**uppercase**Converts the given string to all uppercase**capitalize**Capitalize a string**cast**Casts a variable into the given type. Options are: integer, float, string, boolean, object, array and Laravel Collection.**format\_date**Always takes two arguments, the date's given format and the target format, following DateTime notation.**strip\_tags**Strip HTML and PHP tags using php's strip\_tags**digit**Get only digit characters from the string**filter\_if**Applies filters if an attribute exactly matches valueAdding custom filters
---------------------

[](#adding-custom-filters)

You can add your own filters by passing a custom filter array to the Sanitize constructor as the third parameter. For each filter name, either a closure or a full classpath to a Class implementing the Waavi\\Sanitizer\\Contracts\\Filter interface must be provided. Closures must always accept two parameters: $value and an $options array:

```
    class RemoveStringsFilter implements Waavi\Sanitizer\Contracts\Filter
    {
        public function apply($value, $options = [])
        {
            return str_replace($options, '', $value);
        }
    }

    $customFilters = [
        'hash'   =>  function($value, $options = []) {
                return sha1($value);
            },
        'remove_strings' => RemoveStringsFilter::class,
    ];

    $filters = [
        'secret'    =>  'hash',
        'text'      =>  'remove_strings:Curse,Words,Galore',
    ];

    $sanitize = new Sanitize($data, $filters, $customFilters);
```

Install
-------

[](#install)

To install, just run:

```
composer require waavi/sanitizer ~1.0

```

And you're done! If you're using Laravel, in order to be able to access some extra functionality you must register both the Service provider in the providers array in config/app.php, as well as the Sanitizer Facade:

```
    'providers' => [
        ...
        Waavi\Sanitizer\Laravel\SanitizerServiceProvider::class,
    ];

    'aliases' => [
        ...
        'Sanitizer' => Waavi\Sanitizer\Laravel\Facade::class,
    ];
```

Laravel goodies
---------------

[](#laravel-goodies)

If you are using Laravel, you can use the Sanitizer through the Facade:

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

You can also easily extend the Sanitizer library by adding your own custom filters, just like you would the Validator library in Laravel, by calling extend from a ServiceProvider like so:

```
    \Sanitizer::extend($filterName, $closureOrClassPath);
```

You may also Sanitize input in your own FormRequests by using the SanitizesInput trait, and adding a *filters* method that returns the filters that you want applied to the input.

```
    namespace App\Http\Requests;

    use App\Http\Requests\Request;
    use Waavi\Sanitizer\Laravel\SanitizesInput;

    class SanitizedRequest extends Request
    {
        use SanitizesInput;

        public function filters()
        {
            return [
                'name'  => 'trim|capitalize',
                'email' => 'trim',
                'text'  => 'remove_strings:Curse,Words,Galore',
            ];
        }

        public function customFilters()
        {
            return [
                'remove_strings' => RemoveStringsFilter::class,
            ];
        }

        /* ... */
```

To generate a Sanitized Request just execute the included Artisan command:

```
php artisan make:sanitized-request TestSanitizedRequest

```

The only difference with a Laravel FormRequest is that now you'll have an extra 'fields' method in which to enter the input filters you wish to apply, and that input will be sanitized before being validated.

### License

[](#license)

WAAVI Sanitizer is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

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 ~201 days

Recently: every ~377 days

Total

20

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40a68a3f1473968f24ec70a09cd3a534f657a48e7d65ce187f8af3481c416ce0?d=identicon)[daniser](/maintainers/daniser)

---

Top Contributors

[![sildraug](https://avatars.githubusercontent.com/u/767887?v=4)](https://github.com/sildraug "sildraug (9 commits)")[![zarianec](https://avatars.githubusercontent.com/u/3776001?v=4)](https://github.com/zarianec "zarianec (3 commits)")[![alariva](https://avatars.githubusercontent.com/u/3021314?v=4)](https://github.com/alariva "alariva (2 commits)")[![shekharkhatri](https://avatars.githubusercontent.com/u/44218196?v=4)](https://github.com/shekharkhatri "shekharkhatri (2 commits)")[![TiagoSilvaPereira](https://avatars.githubusercontent.com/u/11933789?v=4)](https://github.com/TiagoSilvaPereira "TiagoSilvaPereira (2 commits)")[![LasseRafn](https://avatars.githubusercontent.com/u/2689341?v=4)](https://github.com/LasseRafn "LasseRafn (1 commits)")[![mozammil](https://avatars.githubusercontent.com/u/1447522?v=4)](https://github.com/mozammil "mozammil (1 commits)")[![norbybaru](https://avatars.githubusercontent.com/u/13020317?v=4)](https://github.com/norbybaru "norbybaru (1 commits)")[![sharifzadesina](https://avatars.githubusercontent.com/u/205923701?v=4)](https://github.com/sharifzadesina "sharifzadesina (1 commits)")[![Tlapi](https://avatars.githubusercontent.com/u/2815391?v=4)](https://github.com/Tlapi "Tlapi (1 commits)")[![francoism90](https://avatars.githubusercontent.com/u/5028905?v=4)](https://github.com/francoism90 "francoism90 (1 commits)")[![smknstd](https://avatars.githubusercontent.com/u/2412608?v=4)](https://github.com/smknstd "smknstd (1 commits)")[![Spodnet](https://avatars.githubusercontent.com/u/3228770?v=4)](https://github.com/Spodnet "Spodnet (1 commits)")[![fomvasss](https://avatars.githubusercontent.com/u/19834478?v=4)](https://github.com/fomvasss "fomvasss (1 commits)")[![grpaiva](https://avatars.githubusercontent.com/u/4790659?v=4)](https://github.com/grpaiva "grpaiva (1 commits)")[![jijoel](https://avatars.githubusercontent.com/u/3487641?v=4)](https://github.com/jijoel "jijoel (1 commits)")

---

Tags

laravelinputsanitationinput filterinput sanitationinput sanitizertransform input

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

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

Data sanitizer and Laravel 7 form requests with input sanitation.

433589.2k4](/packages/waavi-sanitizer)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M106](/packages/propaganistas-laravel-phone)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)

PHPackages © 2026

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