PHP code example of zachleigh / laravel-laundromat

1. Go to this page and download the library: Download zachleigh/laravel-laundromat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zachleigh / laravel-laundromat example snippets


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');
});

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

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

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

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

class User extends Model
{
    use Washable;
    
    //
}

$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"
//}


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

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

$user = User::find(1);

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

class User extends Model
{
    use Washable;

    protected $defaultCleaner = MyCustomCleaner::class;
    
    //
}

php artisan laundromat:create CleanUser