PHPackages                             zachleigh/laravel-laundromat - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zachleigh/laravel-laundromat

AbandonedArchivedProject[Utility &amp; Helpers](/categories/utility)

zachleigh/laravel-laundromat
============================

Clean up objects before sending them client-side.

v1.2.1(9y ago)221MITPHPPHP &gt;=5.5.9

Since Jul 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/zachleigh/laravel-laundromat)[ Packagist](https://packagist.org/packages/zachleigh/laravel-laundromat)[ RSS](/packages/zachleigh-laravel-laundromat/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

Laravel Laundromat
==================

[](#laravel-laundromat)

[![Latest Stable Version](https://camo.githubusercontent.com/3577c42b412e46a8ae5237978019ef20650160af255108fad63e3fe2f2dbbff1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6163686c656967682f6c61726176656c2d6c61756e64726f6d61742e737667)](//packagist.org/packages/zachleigh/laravel-laundromat)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](//packagist.org/packages/zachleigh/laravel-laundromat)[![Build Status](https://camo.githubusercontent.com/031ddc8ffc3bea49ff8506410c3cebcb8c1dcf49f89523146ef8adafb8f6d396/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6163686c656967682f6c61726176656c2d6c61756e64726f6d61742f6d61737465722e737667)](https://travis-ci.org/zachleigh/laravel-laundromat)[![SensioLabsInsight](https://camo.githubusercontent.com/f84d991cdff8859d20b98485b5c9ca64ddc81852e9cf1e0968c4ee05769955e8/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f62643061353965362d326238652d343934392d393336362d3964396634396337326239322e737667)](https://insight.sensiolabs.com/projects/bd0a59e6-2b8e-4949-9366-9d9f49c72b92)[![Quality Score](https://camo.githubusercontent.com/f58c2d732e442f3241c18f9b98b963413b4a4714f0b1e8f920270e5e40c477b0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6163686c656967682f6c61726176656c2d6c61756e64726f6d61742e737667)](https://scrutinizer-ci.com/g/zachleigh/laravel-laundromat/)[![StyleCI](https://camo.githubusercontent.com/3f4f1bdcda71cc689f7406e8470ca744f1c08c98e5e8265f50727d8a1c62e650/68747470733a2f2f7374796c6563692e696f2f7265706f732f36343036353433342f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/64065434)

##### Take your objects to the cleaners before sending them clientside.

[](#take-your-objects-to-the-cleaners-before-sending-them-clientside)

This package gives you an easy way to filter your objects to remove sensitve data before sending them client-side.

### Contents

[](#contents)

- [Demo](#demo)
- [Upgrade Information](#upgrade-information)
- [Install](#install)
- [Contributing](#contributing)

### Demo

[](#demo)

Our user migration looks like this:

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('username')->unique();
    $table->string('email')->unique();
    $table->string('social_security_number');
    $table->date('birthday');
    $table->string('password');
    $table->integer('family_id')->unsigned();
    $table->rememberToken();
    $table->timestamps();

    $table->foreign('family_id')->references('id')->on('families');
});
```

And our User model looks like this:

```
class User extends Model
{
    protected $casts = [
        'birthday' => 'date'
    ];

    public function family()
    {
        return $this->belongsTo(Family::class);
    }

    public function readableBirthday()
    {
        return $this->birthday->toFormattedDateString();
    }
}
```

We obviously don't want to send sensitive data like `social_security_number` to the front end where it would be viewable by anybody. Maybe we only want to expose `username` from the user model and then `last_name` on the related family model. Also, we want to use the value returned from the `readableBirthday()` method on the model.

First, make a new Cleaner class. The naming convention is 'Clean' plus the name of the model:

```
php artisan laundromat:create CleanUser

```

This will give you an empty cleaner class in app/Cleaners. Simply register allowed properties in the `allowed` array and register any methods you wish to run in `methods`. Use dot syntax to indicate properties/methods on relationships.

```
class CleanUser extends Cleaner
{
    /**
     * Properties allowed on the clean object.
     *
     * @var array
     */
    protected $allowed = [
        'username',
        'family.last_name'
    ];

    /**
     * Methods to run. Returned value will be stored as a snake case property
     * on the clean object.
     *
     * @var array
     */
    protected $methods = [
        'readableBirthday'
    ];
}

```

Use the Washable trait in your User model.

```
use LaravelLaundromat\Washable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Washable;

    //
}
```

Then call the `clean()` method on a User object to get a CleanUser instance.

```
$user = User::find(1);

$clean = $user->clean();

var_dump($clean);

// App\Cleaners\CleanUser {
//  "username" => "bettylou"
//  "family" => LaravelLaundromat\EmptyCleaner {
//    "last_name" => "McGraw"
//  }
//  "readable_birthday" => "Jul 15, 1985"
//}
```

Or, use the Collection macro `clean()`:

```
$users = User::all(); // $users is a collection

$clean = $users->clean(); // All User objects in the collection are now CleanUser objects
```

Pass `clean()` (either the normal method or the collection macro) an optional cleaner name to override default behavior.

```
$user = User::find(1);

$clean = $user->clean('App/MyDirectory/MyCustomCleaner'); // $clean is now an instance of MyCustomCleaner
```

Or, add the property `defaultCleaner` to the model to permanently set override the conventional behavior.

```
class User extends Model
{
    use Washable;

    protected $defaultCleaner = MyCustomCleaner::class;

    //
}
```

### Upgrade Information

[](#upgrade-information)

##### From 1.1.\* to 1.2.0

[](#from-11-to-120)

Version 1.2.0 adds Laravel 5.4 support. For Laravel 5.3, please use [Version 1.1.0](https://github.com/zachleigh/laravel-laundromat/tree/v1.1.0):

```
composer require zachleigh/laravel-laundromat:1.1.*

```

##### From 1.0.\* to 1.1.0

[](#from-10-to-110)

Version 1.1.0 adds Laravel 5.3 support. For Laravel 5.2, please use [Version 1.0.2](https://github.com/zachleigh/laravel-laundromat/tree/v1.0.2):

```
composer require zachleigh/laravel-laundromat:1.0.*

```

### Install

[](#install)

Install via composer:

```
composer require zachleigh/laravel-laundromat

```

Register the service provider in config/app.php:

```
'providers' => [
    ...
    LaravelLaundromat\LaundromatServiceProvider::class,
];

```

### Contributing

[](#contributing)

Contributions are more than welcome. Fork, improve, add tests, and make a pull request.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Recently: every ~26 days

Total

6

Last Release

3438d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00a76b63e84a85f8770b1b02b1190c03400c48528f0c33262f7789d35eca875d?d=identicon)[zachleigh](/maintainers/zachleigh)

---

Top Contributors

[![zachleigh](https://avatars.githubusercontent.com/u/5616626?v=4)](https://github.com/zachleigh "zachleigh (22 commits)")

---

Tags

laravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zachleigh-laravel-laundromat/health.svg)

```
[![Health](https://phpackages.com/badges/zachleigh-laravel-laundromat/health.svg)](https://phpackages.com/packages/zachleigh-laravel-laundromat)
```

###  Alternatives

[stephenjude/filament-blog

Filament Blog Builder

20618.8k](/packages/stephenjude-filament-blog)[datomatic/nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.

11258.1k](/packages/datomatic-nova-detached-actions)

PHPackages © 2026

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