Download the PHP package origami/money without Composer
On this page you can find all versions of the php package origami/money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download origami/money
More information about origami/money
Files in origami/money
Package money
Short Description Money handling and formatting package for Laravel projects
License MIT
Informations about the package money
Origami Money for Laravel
This package is a money helper for Laravel projects and a wrapper around moneyphp/money.
Installation
Install this package through Composer.
Requirements
- This package is designed to work with Laravel >= 8.
- The
ext-intl
PHP extension is required.
Configuration
First, publish the default configuration.
This will add a new configuration file to: config/money.php
which contains a default_currency
value.
Usage
Value Object
The Origami\Money\Money
value object class is a helper that uses a Money\Money
object (from moneyphp/money) under the hood. This allows us to add some helper methods (e.g. for formatting) and be more opinionated about our implementation. The class does not extend Money\Money
since that is a final class
- instead we use an internal attribute.
As with Money\Money
, each Origami\Money\Money
object requires an:
$amount
, expressed in the smallest units of $currency (eg cents)$currency
, an ISO-4217 3 character code for currency.
For example:
You can also pass a moneyphp object:
Available Methods
instance
Create an instance from Money\Money
object:
copy
Create a copy of the instance
asBase
Get the underlying Money\Money
object
isSameCurrency
equals
greaterThan / gt
greaterThanOrEqual / gte
lessThan / lt
lessThanOrEqual / lte
isZero
isPositive
isNegative
percentageOf
Set $overflow
argument to false
to not go over 100
getAmount
Returns integer
getCurrency
Returns Money\Money
currency value object
getCurrencyCode
add
subtract
multiply
divide
mod
Modulus operation
ratioOf
Provides the ratio of a Money object compared to another
absolute
negative
Formatting
String
Uses Intl formatter for currency symbol and separatator.
String Neat (without Trailing Zeros)
Only drops trailing zeros were decimal is zero.
Decimal
Blade Directives
You can use the following directives in your Blade views:
Eloquent Attribute Cast
You are most likely storing your money values in your Eloquent models. This package provides an Origami\Money\Casts\Money
custom Laravel cast for you to use:
In the example above, you can set the total
attributes using a Money object:
In the example above, $invoice->total
will be an instance of:
You can also use a float, string or integer value when setting the casted attribute - for example from a controller.
Important: This will use the Origami\Money\MoneyHelper@input
method behind the scenes (which ultimately uses Origami\Money\MoneyHelper@adjustAmount
), transforming the amount to the smallest unit of currency after assuming it is given as dollars or pounds, for example.
Your model should have a currency
attribute or a getCurrencyCode
method with / which returns the ISO-4217 code. Otherwise, this package will default to the default_currency
set in the config file.
The above therefore converts to:
If your controllers or other methods already expect user input in cents rather than dollars, you should either not use the cast or instead pass an Origami\Money\Money
object instead of the numerical amount (which would be tranformed).
Versions
- v2.* - Version 2 is a breaking change rewrite of the package to include better formatting and helper value object class.
- v1.-* - Version 1 offered basic formatting and was compatible with Laravel 6-9.
Author
License
All versions of money with dependencies
ext-intl Version *
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
moneyphp/money Version ^3.3