2017 © Pedro Peláez
 

library decimal-mutators

Add a short way to create accessors and mutators for decimal fields

image

giordanolima/decimal-mutators

Add a short way to create accessors and mutators for decimal fields

  • Monday, June 5, 2017
  • by giordanolima
  • Repository
  • 3 Watchers
  • 8 Stars
  • 314 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

Latest Stable Version Total Downloads License StyleCI, (*1)

Decimal Mutators for Laravel

Decimal Mutators provides a short way to create accessors and mutators for decimal fields., (*2)

Install

Install package through Composer, (*3)

composer require giordanolima/decimal-mutators

Usage

You should use it as a trait of your model, and declare which fields you want to apply the mutators:, (*4)

use Illuminate\Database\Eloquent\Model,
    GiordanoLima\DecimalMutators\DecimalMutators;
class MyModel extends Model
{
    use DecimalMutators;

    protected $decimalsFields = [
            'decimal_field_1',
            'decimal_field_2',
            'decimal_field_3',
            'decimal_field_4'
        ];

}

By default, the trait will get the data from database and will replace "," (comma) as thousand separator to ""(blank) and will replace "." (dot) as decimal separator to "," (comma). The behavior will be like this:, (*5)

$myModel = MyModel::find(1);
$myModel->decimal_field_1 = '200,00';
$myModel->save(); // It will store as 200.00

$myModel = MyModel::find(1);
echo $myModel->decimal_field_1; // Will print 200,00

By default, it gonna be used 2 for decimal points... If you need change it, you can set the option:, (*6)

protected $decimalsOptions = [
    "decimals" => 4, // now, the fields will be stored and printed with 4 decimals point
];

If you want to replace defaults separators, you can replace with:, (*7)

protected $decimalsOptions = [
    "setDecimalsFrom" => ",",
    "setDecimalsTo" => ".",
    "setThounsandFrom" => ".",
    "setThounsandTo" => "",
    "getDecimalsFrom" => ".",
    "getDecimalsTo" => ",",
    "getThounsandFrom" => ",",
    "getThounsandTo" => "",
];

You can disable the mutators:, (*8)

MyModel::$disableGetMutator = true;
echo $myModel->decimal_field_1; // Will print 200.00
MyModel::$disableGetMutator = false;
echo $myModel->decimal_field_1; // Will print 200,00
MyModel::$disableSetMutator = true;
$myModel->decimal_field_1 = '200,00';
$myModel->save(); // It will store as 200,00
MyModel::$disableSetMutator = false;
$myModel->decimal_field_1 = '200,00';
$myModel->save(); // It will store as 200.00

The Versions

05/06 2017

dev-master

9999999-dev

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

05/06 2017

1.1.1

1.1.1.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

20/07 2016

1.1.0

1.1.0.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

20/07 2016

dev-analysis-qo7V27

dev-analysis-qo7V27

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

14/01 2016

1.0.x-dev

1.0.9999999.9999999-dev

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

14/01 2016

1.0.3

1.0.3.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

15/12 2015

1.0.2

1.0.2.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

11/12 2015

1.0.1

1.0.1.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals

08/12 2015

1.0.0

1.0.0.0

Add a short way to create accessors and mutators for decimal fields

  Sources   Download

MIT

The Requires

 

by Giordano de Andrades Lima

laravel eloquent laravel5 accessor mutator decimal accessors mutators decimals