aharen / laravel-money
Simple class with Facade to handle money for Laravel 5.2
Requires
- php: ^7.3|^8.0
- illuminate/support: ^7.0|^8.0|^9.0
Requires (Dev)
- graham-campbell/testbench: ^5.7
- phpunit/phpunit: ^8.5|^9.5.10
This package is auto-updated.
Last update: 2024-10-21 09:25:27 UTC
README
Simple class with Facade to handle money for Laravel 5. The class stores and calculates all money related value (eg: prices etc..) in Laari (Pennies)
Installation
composer require aharen/laravel-money
Configuration
-
Add
MoneyServiceProvider
toproviders
inconfig/app.php
aharen\Money\MoneyServiceProvider::class,
-
Add
Money
Facade toaliases
inconfig/app.php
Money => aharen\Money\MoneyManagerFacade::class,
Usage
Initiate from either Rufiyaa
$money = Money::fromRufiyaa(10);
or Laari
$money = Money::fromLaari(1000);
Addition
Expects the provided ammount to be added in Laari
Money::fromRufiyaa(20) ->add(100) // 1 rufiyaa ->inRufiyaa();
Adding other money objects
Money::fromRufiyaa(20) ->add(Money::fromRufiyaa(20.5)) ->inRufiyaa();
Subtraction
Expects the provided ammount to be subtracted in Laari
Money::fromRufiyaa(20) ->subtract(100) // 1 rufiyaa ->inRufiyaa();
Subtracting other money objects
Money::fromRufiyaa(20) ->subtract(Money::fromRufiyaa(5) ->inRufiyaa();
Multiplication
Expects the provided ammount to be multiplied in Laari
Money::fromRufiyaa(2) ->multiply(200) // 2 rufiyaa ->inRufiyaa();
Multiplying other money objects
Money::fromRufiyaa(20) ->multiply(Money::fromRufiyaa(5)) ->inRufiyaa();
Division
Expects the provided ammount to be multiplied in Laari
Money::fromRufiyaa(4) ->divide(200) // 2 rufiyaa ->inRufiyaa();
Dividing other money objects
Money::fromRufiyaa(4) ->divide(Money::fromRufiyaa(2)) ->inRufiyaa();
Chaining Methods
You have the ability to manipulate the values in a chainable way.
Money::fromRufiyaa(20) ->add(200) // 2 rufiyaa ->subtract(100) // 1 rufiyaa ->inRufiyaa();
Output
There are 3 output options available:
- Output in Laari
$money->inLaari();
- Output in Rufiyaa
$money->inRufiyaa();
- Output in Rufiyaa and Laari
$money->inRufiyaaAndLaari();