PHPackages                             hasfoug/laravel-money - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hasfoug/laravel-money

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hasfoug/laravel-money
=====================

Laravel Money

2.0.2(4mo ago)05.0k↓33.3%MITPHPPHP ^8.0CI failing

Since Mar 29Pushed 4mo agoCompare

[ Source](https://github.com/hasfoug/laravel-money)[ Packagist](https://packagist.org/packages/hasfoug/laravel-money)[ Docs](https://github.com/hasfoug/laravel-money)[ RSS](/packages/hasfoug-laravel-money/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (16)Used By (0)

Laravel Money
=============

[](#laravel-money)

[![License](https://camo.githubusercontent.com/82fa87f9c8bbc19ff0ea486868c85a1c784a687782e7a8d9af33dd511c190696/68747470733a2f2f706f7365722e707567782e6f72672f636b6e6f772f6c61726176656c2d6d6f6e65792f6c6963656e7365)](https://packagist.org/packages/cknow/laravel-money)

> **Note:** This project is based on [cknow/laravel-money](https://github.com/cknow/laravel-money) and abstracts [MoneyPHP](http://moneyphp.org/)

Installation
------------

[](#installation)

Run the following command from you terminal:

```
composer require hasfoug/laravel-money
```

Usage
-----

[](#usage)

```
use Hasfoug\Money\Money;

echo Money::USD(500); // $5.00
echo Money::USD(500, true); // $500.00 force decimals
```

Configuration
-------------

[](#configuration)

The defaults are set in `config/money.php`. Copy this file to your own config directory to modify the values. You can publish the config using this command:

```
php artisan vendor:publish --provider="Hasfoug\Money\MoneyServiceProvider"
```

This is the contents of the published file:

```
return [
    /*
     |--------------------------------------------------------------------------
     | Laravel money
     |--------------------------------------------------------------------------
     */
    'locale' => config('app.locale', 'en_US'),
    'defaultCurrency' => config('app.currency', 'USD'),
    'defaultFormatter' => null,
    'defaultSerializer' => null,
    'currencies' => [
        'iso' => ['RUB', 'USD', 'EUR'],  // 'all' to choose all ISOCurrencies
        'bitcoin' => ['XBT'], // 'all' to choose all BitcoinCurrencies
        'custom' => [
            'MY1' => 2,
            'MY2' => 3
        ]
    ]
];
```

Main changes to the cknow/laravel-money version:
------------------------------------------------

[](#main-changes-to-the-cknowlaravel-money-version)

### Most operations now accept mixed values, parsing them to default currency before operation

[](#most-operations-now-accept-mixed-values-parsing-them-to-default-currency-before-operation)

Therefore, you are not required need to convert the operands to money instance anymore (unless you operate in non-default currency):

```
Money::USD(500)->add(100); // $6.00
Money::USD(500)->add(null); // $5.00
Money::USD(500)->subtract(100); // $4.00
Money::USD(500)->subtract(null); // $5.00

// Aggregation
Money::min(Money::USD(100), Money::USD(200), 300, null); // Money::USD(0)
Money::max(Money::USD(100), Money::USD(200), 400); // Money::USD(400)
Money::avg(Money::USD(100), Money::USD(200), 300); // Money::USD(200)
Money::sum(Money::USD(100), Money::USD(200), 300, null, 0); // Money::USD(600)

// Comparing
Money::USD(500)->equals(500); // true
Money::USD(500)->greaterThan(100); // true
Money::USD(500)->greaterThan(null); // true
Money::USD(500)->greaterThanOrEqual(500); // true
Money::USD(500)->lessThan(1000); // true
Money::USD(500)->lessThan(null); // false
Money::USD(500)->lessThanOrEqual(500); // true
Money::USD(0)->lessThanOrEqual(null); // true
```

### Added shortcuts for comparing operations

[](#added-shortcuts-for-comparing-operations)

```
Money::USD(500)->eq(500); // true
Money::USD(500)->gt(100); // true
Money::USD(500)->gte(500); // true
Money::USD(500)->lt(1000); // true
Money::USD(500)->lte(500); // true
```

### Added isNotZero accessor

[](#added-isnotzero-accessor)

```
Money::USD(500)->isNotZero(); // true
Money::USD(0)->isNotZero(); // false
```

### getAmount() method return type switched to int

[](#getamount-method-return-type-switched-to-int)

```
Money::USD(500)->getAmount(); // '500' -> Before
Money::USD(500)->isNotZero(); // 500 -> Now
```

### Added defaultSerializer to the config to set default json serialization behaviour

[](#added-defaultserializer-to-the-config-to-set-default-json-serialization-behaviour)

Change the value of money.defaultSerializer setting to one of those values:

- \\Hasfoug\\Money\\Tests\\Serializers\\ArrayMoneySerializer::class
- \\Hasfoug\\Money\\Tests\\Serializers\\DecimalMoneySerializer::class
- \\Hasfoug\\Money\\Tests\\Serializers\\IntegerMoneySerializer::class
- \\Hasfoug\\Money\\Tests\\Serializers\\StringMoneySerializer::class

Or create your own, which should implement \\Hasfoug\\Money\\Contracts\\MoneySerializer

Advanced Usage
--------------

[](#advanced-usage)

> See [MoneyPHP](http://moneyphp.org/) for more information

```
use Hasfoug\Money\Money;

Money::USD(500)->add(Money::USD(500)); // $10.00
Money::USD(500)->add(Money::USD(500), Money::USD(500)); // $15.00
Money::USD(500)->subtract(Money::USD(400)); // $1.00
Money::USD(500)->subtract(Money::USD(200), Money::USD(100)); // $2.00
Money::USD(500)->multiply(2); // $10.00
Money::USD(1000)->divide(2); // $5.00
Money::USD(830)->mod(Money::USD(300)); // $2.30 -> Money::USD(230)
Money::USD(-500)->absolute(); // $5.00
Money::USD(500)->negative(); // $-5.00
Money::USD(30)->ratioOf(Money::USD(2)); // 15
Money::USD(500)->isSameCurrency(Money::USD(100)); // true
Money::USD(500)->equals(Money::USD(500)); // true
Money::USD(500)->greaterThan(Money::USD(100)); // true
Money::USD(500)->greaterThanOrEqual(Money::USD(500)); // true
Money::USD(500)->lessThan(Money::USD(1000)); // true
Money::USD(500)->lessThanOrEqual(Money::USD(500)); // true
Money::USD(500)->isZero(); // false
Money::USD(500)->isPositive(); // true
Money::USD(500)->isNegative(); // false
Money::USD(500)->getMoney(); // Instance of \Money\Money
Money::isValidCurrency('USD'); // true
Money::isValidCurrency('FAIL'); // false
Money::getISOCurrencies(); // Load ISO currencies

// Aggregation
Money::min(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(100)
Money::max(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(300)
Money::avg(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(200)
Money::sum(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(600)

// Formatters
Money::USD(500)->format(); // $5.00
Money::USD(199)->format(null, null, \NumberFormatter::DECIMAL); // 1,99
Money::XBT(41000000)->formatByBitcoin(); // \xC9\x830.41
Money::USD(500)->formatByCurrencySymbol(); // $5.00
Money::USD(500)->formatByCurrencySymbol(true); // 5.00$
Money::USD(500)->formatByDecimal(); // 5.00
Money::USD(500)->formatByIntl(); // $5.00
Money::USD(199)->formatByIntl(null, null, \NumberFormatter::DECIMAL); // 1,99
Money::USD(500)->formatByIntlLocalizedDecimal(); // $5.00
Money::USD(199)->formatByIntlLocalizedDecimal(null, null, \NumberFormatter::DECIMAL) // 1.99

// Parsers
Money::parse('$1.00'); // Money::USD(100)
Money::parseByBitcoin("\xC9\x830.41"); // Money::XBT(41000000)
Money::parseByDecimal('1.00', 'USD'); // Money::USD(100)
Money::parseByIntl('$1.00'); // Money::USD(100)
Money::parseByIntlLocalizedDecimal('1.00', 'USD'); // Money::USD(100)
```

### Create your formatter

[](#create-your-formatter)

```
class MyFormatter implements \Money\MoneyFormatter
{
    public function format(\Money\Money $money)
    {
        return 'My Formatter';
    }
}

Money::USD(500)->formatByFormatter(new MyFormatter()); // My Formatter
```

Rules
-----

[](#rules)

Below is a list of all available validation rules and their function:

### currency

[](#currency)

The field under validation must be a valid currency.

```
Validator::make([
  'currency1' => 'USD',
  'currency2' => 'EUR',
  'currency3' => new \Money\Currency('BRL'),
], [
  'currency1' => new \Hasfoug\Money\Rules\Currency(),
  'currency2' => new \Hasfoug\Money\Rules\Currency(),
  'currency3' => 'currency',
]);
```

### money

[](#money)

The field under validation must be a valid money.

```
Validator::make([
  'money1' => '$10.00'
  'money2' => '€10.00',
  'money3' => 'R$10,00',
  'money4' => '$10.00'
  'money5' => '€10.00',
  'money6' => 'R$10,00',
], [
  'money1' => new \Hasfoug\Money\Rules\Money(),
  'money2' => new \Hasfoug\Money\Rules\Money('EUR'), // forcing currency
  'money3' => new \Hasfoug\Money\Rules\Money('BRL', 'pt_BR'), // forcing currency and locale
  'money4' => 'money',
  'money5' => 'money:EUR', // forcing currency
  'money6' => 'money:BRL,pt_BR', // forcing currency and locale
]);
```

Casts
-----

[](#casts)

At this stage the cast can be defined in the following ways:

```
use Hasfoug\Money\Casts\MoneyDecimalCast;
use Hasfoug\Money\Casts\MoneyIntegerCast;
use Hasfoug\Money\Casts\MoneyStringCast;

protected $casts = [
    // cast money as decimal using the currency defined in the package config
    'money' => MoneyDecimalCast::class,
    // cast money as integer using the defined currency
    'money' => MoneyIntegerCast::class . ':AUD',
    // cast money as string using the currency defined in the model attribute 'currency'
    'money' => MoneyStringCast::class . ':currency',
    // cast money as decimal using the defined currency and forcing decimals
    'money' => MoneyDecimalCast::class . ':USD,true',
];
```

In the example above, if the model attribute `currency` is `null`, the currency defined in the package configuration is used instead.

Setting money can be done in several ways:

```
$model->money = 10; // 0.10 USD or any other currency defined
$model->money = 10.23; // 10.23 USD or any other currency defined
$model->money = 'A$10'; // 10.00 AUD
$model->money = '1,000.23'; // 1000.23 USD or any other currency defined
$model->money = '10'; // 0.10 USD or any other currency defined
$model->money = Money::EUR(10); // 10 EUR
```

When we pass the model attribute holding the currency, such attribute is updated as well when setting money:

```
$model->currency; // null
$model->money = '€13';
$model->currency; // 'EUR'
$model->money->getAmount(); // '1300'
```

Helpers
-------

[](#helpers)

```
currency() // To use default currency present in `config/money.php`
currency('USD');
money(500); // To use default currency present in `config/money.php`
money(500, 'USD');

// Aggregation
money_min(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(100)
money_max(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(300)
money_avg(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(200)
money_sum(money(100, 'USD'), money(200, 'USD'), money(300, 'USD')); // Money::USD(600)

// Parsers
money_parse('$5.00'); // Money::USD(500)
money_parse_by_bitcoin("\xC9\x830.41"); // Money::XBT(41000000)
money_parse_by_decimal('1.00', 'USD'); // Money::USD(100)
money_parse_by_intl('$1.00'); // Money::USD(100)
money_parse_by_intl_localized_decimal('1.00', 'USD'); // Money::USD(100)
```

Blade Extensions
----------------

[](#blade-extensions)

```
@currency() // To use default currency present in `config/money.php`
@currency('USD')
@money(500) // To use default currency present in `config/money.php`
@money(500, 'USD')

// Aggregation
@money_min(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(100)
@money_max(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(300)
@money_avg(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(200)
@money_sum(@money(100, 'USD'), @money(200, 'USD'), @money(300, 'USD')) // Money::USD(600)

// Parsers
@money_parse('$5.00') // Money::USD(500)
@money_parse_by_bitcoin("\xC9\x830.41") // Money::XBT(41000000)
@money_parse_by_decimal('1.00', 'USD') // Money::USD(100)
@money_parse_by_intl('$1.00') // Money::USD(100)
@money_parse_by_intl_localized_decimal('1.00', 'USD') // Money::USD(100)
```

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance75

Regular maintenance activity

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~71 days

Recently: every ~152 days

Total

15

Last Release

146d ago

Major Versions

1.4.0 → 2.0.02025-05-13

PHP version history (2 changes)1.0.0PHP ^7.3|^8.0

1.1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/03b05bcdb9045a5f7d64c33477d9d5b417710211f98e532f2638006478664bcb?d=identicon)[hasfoug](/maintainers/hasfoug)

---

Top Contributors

[![ricardogobbosouza](https://avatars.githubusercontent.com/u/13064722?v=4)](https://github.com/ricardogobbosouza "ricardogobbosouza (296 commits)")[![hasfoug](https://avatars.githubusercontent.com/u/26816621?v=4)](https://github.com/hasfoug "hasfoug (14 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (4 commits)")[![tymondesigns](https://avatars.githubusercontent.com/u/1801923?v=4)](https://github.com/tymondesigns "tymondesigns (3 commits)")[![russofinn](https://avatars.githubusercontent.com/u/16693017?v=4)](https://github.com/russofinn "russofinn (2 commits)")[![Kurre](https://avatars.githubusercontent.com/u/1389199?v=4)](https://github.com/Kurre "Kurre (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![markahesketh](https://avatars.githubusercontent.com/u/1269894?v=4)](https://github.com/markahesketh "markahesketh (1 commits)")[![A-Ghorab](https://avatars.githubusercontent.com/u/9165404?v=4)](https://github.com/A-Ghorab "A-Ghorab (1 commits)")[![niklaslovgren](https://avatars.githubusercontent.com/u/47850368?v=4)](https://github.com/niklaslovgren "niklaslovgren (1 commits)")[![rez1dent3](https://avatars.githubusercontent.com/u/5111255?v=4)](https://github.com/rez1dent3 "rez1dent3 (1 commits)")[![ShamarKellman](https://avatars.githubusercontent.com/u/4120411?v=4)](https://github.com/ShamarKellman "ShamarKellman (1 commits)")[![Skullbock](https://avatars.githubusercontent.com/u/1104083?v=4)](https://github.com/Skullbock "Skullbock (1 commits)")[![subdesign](https://avatars.githubusercontent.com/u/691695?v=4)](https://github.com/subdesign "subdesign (1 commits)")[![sudkumar](https://avatars.githubusercontent.com/u/6812992?v=4)](https://github.com/sudkumar "sudkumar (1 commits)")[![marwins](https://avatars.githubusercontent.com/u/20090626?v=4)](https://github.com/marwins "marwins (1 commits)")[![andreiio](https://avatars.githubusercontent.com/u/1569300?v=4)](https://github.com/andreiio "andreiio (1 commits)")[![AndreSchwarzer](https://avatars.githubusercontent.com/u/6991100?v=4)](https://github.com/AndreSchwarzer "AndreSchwarzer (1 commits)")[![cerbero90](https://avatars.githubusercontent.com/u/5838106?v=4)](https://github.com/cerbero90 "cerbero90 (1 commits)")[![DavidLambauer](https://avatars.githubusercontent.com/u/1841317?v=4)](https://github.com/DavidLambauer "DavidLambauer (1 commits)")

---

Tags

laravelmoneycurrency

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hasfoug-laravel-money/health.svg)

```
[![Health](https://phpackages.com/badges/hasfoug-laravel-money/health.svg)](https://phpackages.com/packages/hasfoug-laravel-money)
```

###  Alternatives

[cknow/laravel-money

Laravel Money

1.0k4.3M22](/packages/cknow-laravel-money)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[torann/currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.

4081.1M6](/packages/torann-currency)[casinelli/currency

Handles currency for Laravel 5.

1911.8k](/packages/casinelli-currency)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
