PHPackages                             sorokin-fm/laravel-request-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. sorokin-fm/laravel-request-sanitizer

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

sorokin-fm/laravel-request-sanitizer
====================================

Laravel Request Sanitizer

1.0(7y ago)030PHPPHP &gt;=7.1

Since Jan 7Pushed 7y agoCompare

[ Source](https://github.com/sorokin-fm/laravel-request-sanitizer)[ Packagist](https://packagist.org/packages/sorokin-fm/laravel-request-sanitizer)[ RSS](/packages/sorokin-fm-laravel-request-sanitizer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

We all know that the thinner is controller the better it is. And we wanted to have such controllers:

```
    public function update(UpdateRequest $request, $id)
    {
        /** @var SomeModel $model */
        $model = SomeModel::find($id);
        $model->fill($request->input());
        $model->save();

        return back()
            ->with('success', __('Some model has been changed'));
    }

```

Unfortunately, there's a couple of cases, where we just can't directly pass inputs to fill.

For example, some fields are checkboxes. So we need to do a little pre-processing:

```
$values = $request->input();
$values['checkbox1'] = $values['checkbox1'] ? 1 : 0;
$values['checkbox2'] = $values['checkbox2'] ? 1 : 0;
$model->fill($values);

```

Another scenario is when we need to upload files:

```
$values = $request->input();

$file = $request->file('picture');
if ($file) {
    $filename = Transliteration::make(
        pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
        ['type' => 'filename', 'lowercase' => true]);

    $filename .= '.' . $file->getClientOriginalExtension();

    $file->move($filePath, $filename);

    $values['picture'] = $filename;
}

$file = $request->file('thumb');
if ($file) {
    $filename = Transliteration::make(
        pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
        ['type' => 'filename', 'lowercase' => true]);

    $filename .= '.' . $file->getClientOriginalExtension();

    $file->move($filePath, $filename);

    $values['thumb'] = $filename;
}

$model->fill($values);

```

As you see, it's not very thin, yes? And the worst - we need to duplicate that code in store and update actions. So what can we do with all of this to make it better?

For - add this package:

```
compose require "sorokin-fm/laravel-request-sanitizer"

```

And then, add it to you request class:

```
use Illuminate\Foundation\Http\FormRequest;
use SorokinFM\RequestSanitizerTrait;

class StoreRequest extends FormRequest

    use RequestSanitizerTrait;
    const SANITIZE_RULES = [
        'enabled' => 'checkbox',
        'picture' => 'file:path/to/store',
    ];

    ...

```

Now you're ready to use it:

```
    public function update(UpdateRequest $request, $id)
    {
        /** @var SomeModel $model */
        $model = SomeModel::find($id);
        $model->fill($request->sanitize());
        $model->save();

        return back()
            ->with('success', __('Some model has been changed'));
    }

```

Of course, if you need to define your own sanitizer, you can implement interface SorokinFM\\SanitizerInterface and then specify full class name ( with namespace ) as rule name, for example:

```
    use RequestSanitizerTrait;
    const SANITIZE_RULES = [
        'enabled' => 'checkbox',
        'picture' => 'file:path/to/store',
        'custom_data' => '\App\Sanitizers\CustomRequestSanitizer',
    ];

```

And one more thing. You also can use wildcards at field names. It will be useful at localization, when you don't know all names of field:

```
    use RequestSanitizerTrait;
    const SANITIZE_RULES = [
        'enabled' => 'checkbox',
        'picture:*' => 'file:path/to/store',
        'custom_data' => '\App\Sanitizers\CustomRequestSanitizer',
    ];

```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

2732d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/46264077?v=4)[sorokin-fm](/maintainers/sorokin-fm)[@sorokin-fm](https://github.com/sorokin-fm)

### Embed Badge

![Health badge](/badges/sorokin-fm-laravel-request-sanitizer/health.svg)

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

###  Alternatives

[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135212.4k7](/packages/statamic-rad-pack-runway)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21313.7k3](/packages/ecotone-laravel)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1040.9k5](/packages/carsdotcom-laravel-json-schema)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3310.1k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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