Download the PHP package zachleigh/laravel-laundromat without Composer
On this page you can find all versions of the php package zachleigh/laravel-laundromat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-laundromat
Laravel Laundromat
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
- Demo
- Upgrade Information
- Install
- Contributing
Demo
Our user migration looks like this:
And our User model looks like this:
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:
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.
Use the Washable trait in your User model.
Then call the clean()
method on a User object to get a CleanUser instance.
Or, use the Collection macro clean()
:
Pass clean()
(either the normal method or the collection macro) an optional cleaner name to override default behavior.
Or, add the property defaultCleaner
to the model to permanently set override the conventional behavior.
Upgrade Information
From 1.1.* to 1.2.0
Version 1.2.0 adds Laravel 5.4 support. For Laravel 5.3, please use Version 1.1.0:
From 1.0.* to 1.1.0
Version 1.1.0 adds Laravel 5.3 support. For Laravel 5.2, please use Version 1.0.2:
Install
Install via composer:
Register the service provider in config/app.php:
Contributing
Contributions are more than welcome. Fork, improve, add tests, and make a pull request.