2017 © Pedro Peláez
 

library laravel-normalizer

Laravel package to normalize your data before saving into the database.

image

nwidart/laravel-normalizer

Laravel package to normalize your data before saving into the database.

  • Thursday, July 28, 2016
  • by nWidart
  • Repository
  • 2 Watchers
  • 9 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

laravel-normalizer

Latest Version on Packagist Software License Build Status Scrutinizer Coverage SensioLabsInsight Quality Score Total Downloads, (*1)

This package helps you normalize your data in order to save them into the database. The Goal is to having separate classes that handle the data normalization, and thus can be tested independently., (*2)

Install

Via Composer, (*3)

``` bash $ composer require nwidart/laravel-normalizer, (*4)


## Usage ### 1. Adding trait Add the `Nwidart\LaravelNormalizer\Traits\CanNormalizeData` trait on the model(s) you wish data to be normalized. ### 2. Create Normalizer classes Your normalizers classes need to implement the `Nwidart\LaravelNormalizer\Contracts\Normalizer` interface. This interface will add the `normalize(array $data)` method. Example: ``` php use Nwidart\LaravelNormalizer\Contracts\Normalizer; final class CustomNormalizer implements Normalizer { /** * Normalize the given data * @param array $data * @return array */ public function normalize(array $data) { if (array_key_exists('name', $data)) { $data['name'] = strtoupper($data['name']); } return $data; } }

This method needs to return the $data array. In here you can change the received data as you please., (*5)

3. Add normalizers class property

On that same model, add a protected $normalizers property. This is where you list your normalizers, in an array., (*6)

Example:, (*7)

``` php use Illuminate\Database\Eloquent\Model; use Nwidart\LaravelNormalizer\Traits\CanNormalizeData;, (*8)

class Product extends Model { use CanNormalizeData; protected $normalizers = [CustomNormalizer::class]; }, (*9)


### 4. Normalize your data on save/update Now you can start normalizing your data. This can for instance be done in your repository class. Example: ``` php public function create($data) { $data = $this->model->normalize($data); return $this->model->create($data); }

Change log

Please see CHANGELOG for more information what has changed recently., (*10)

Testing

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*12)

Security

If you discover any security related issues, please email n.widart@gmail.com instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

28/07 2016

dev-master

9999999-dev https://github.com/nwidart/laravel-normalizer

Laravel package to normalize your data before saving into the database.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel nwidart laravel-normalizer

27/07 2016

0.2

0.2.0.0 https://github.com/nwidart/laravel-normalizer

Laravel package to normalize your data before saving into the database.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel nwidart laravel-normalizer

26/07 2016

0.1

0.1.0.0 https://github.com/nwidart/laravel-normalizer

Laravel package to normalize your data before saving into the database.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel nwidart laravel-normalizer