PHPackages                             desmart/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. desmart/laravel-money

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

desmart/laravel-money
=====================

Manage money in Laravel like a breeze

1.3.0(5y ago)0586MITPHPPHP ^7.4|^8.0

Since Jan 23Pushed 5y ago6 watchersCompare

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

READMEChangelog (4)Dependencies (4)Versions (7)Used By (0)

Laravel Money 💶
===============

[](#laravel-money-)

[![Latest version](https://camo.githubusercontent.com/92f17d42e611245f98b7e481f883b9c322ad942b9a7512561faf93c310d5e394/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465736d6172742f6c61726176656c2d6d6f6e65792e7376673f7374796c653d666c6174)](https://github.com/DeSmart/laravel-money)[![Tests](https://github.com/desmart/laravel-money/workflows/Run%20Tests/badge.svg)](https://github.com/desmart/laravel-money/workflows/Run%20Tests/badge.svg)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/DeSmart/laravel-money/blob/master/LICENSE)

Package provides a simple wrapper around `\Money\Money` objects creation and formatting.

> Minimum Laravel version is **8.12.0**

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

[](#installation)

To install the package via Composer, simply run the following command:

```
composer require desmart/laravel-money

```

Usage
-----

[](#usage)

Package provides three main elements:

- money objects factory,
- money objects formatter,
- money objects casting class.

### Factory

[](#factory)

Factory streamlines `\Money\Money` objects instantiation. `\Money\Money` objects can be created using either integer or float values.

```
\DeSmart\Larvel\Money\MoneyFactory::fromInteger(1000); // New object with the lowest subunit of the (default) currency
\DeSmart\Larvel\Money\MoneyFactory::fromInteger(1000, 'PLN'); // New object with specified currency
```

```
\DeSmart\Larvel\Money\MoneyFactory::fromFloat(10); // New object with 'regular' unit of the (default) currency, i.e. 10.50 USD means 10 dollars and 50 cents
\DeSmart\Larvel\Money\MoneyFactory::fromFloat(10, 'PLN') // New object with specified currency
```

#### Default currency

[](#default-currency)

In case application does not handle multiple currencies, it is recommended to set up default currency to the required one. It speeds up coding and make code less error prone. Default currency can be set up in a very easy way:

```
// For example, in AppServiceProvider.php

\DeSmart\Larvel\Money\MoneyFactory::$defaultCurrency = 'USD'; // Package's default is set to 'EUR'
```

### Formatter

[](#formatter)

To pretty print money value, simply call `\DeSmart\Larvel\Money\MoneyFormatter::prettyPrint($money)`. `prettyPrint`method accepts also a second parameter that indicates if the formatted value should contain html entities - effectively, every space in the formatted value will be replaced with `&nbsp`.

`\DeSmart\Larvel\Money\MoneyFormatter` behind the scenes uses registered formatter class. If no custom class is registered, default `\Money\Formatter\DecimalMoneyFormatter` formatter will be used.

This package ships with an additional formatter, `\DeSmart\Larvel\Money\Formatters\IntlDecimalMoneyFormatter`, which allows defining a particular format in which money value should be presented. There are few defaults (as consts):

- display only amount (`{AMOUNT}`),
- display currency code and amount (`{CURRENCY}{AMOUNT}`),
- display currency code and amount, separated with space (`{CURRENCY}{SPACE}{AMOUNT}`),
- display amount and currency code(`{AMOUNT}{CURRENCY}`),
- display amount and currency code, separated with space (`{AMOUNT}{SPACE}{CURRENCY}`).
- display currency symbol and amount (`{CURRENCY_SYMBOL}{AMOUNT}`),
- display currency symbol and amount, separated with space (`{CURRENCY_SYMBOL}{SPACE}{AMOUNT}`),
- display amount and currency symbol (`{AMOUNT}{CURRENCY_SYMBOL}`),
- display amount and currency symbol, separated with space (`{AMOUNT}{SPACE}{CURRENCY_SYMBOL}`).

Any other format can be used, as long as it utilizes four keywords: `{AMOUNT}`, `{CURRENCY}`, `{CURRENCY_SYMBOL}`, `{SPACE}`. Along with the format, decimal and thousands separators can be defined.

Registering formatter is fairly easy:

```
// For example, in AppServiceProvider.php

\DeSmart\Larvel\Money\MoneyFormatter::formatUsing(
    new \DeSmart\Larvel\Money\Formatters\IntlDecimalMoneyFormatter('{AMOUNT}{CURRENCY}', ',', ' ')
);
```

> Credits to [PruvoNet/price-extractor](https://github.com/PruvoNet/price-extractor) for the currency symbols list.

### Laravel model attribute casting

[](#laravel-model-attribute-casting)

Package provides also a custom casting class that allows to use `\Money\Money` objects with Laravel models.

```
protected $casts = [
    'money' => \DeSmart\Larvel\Money\Casts\Money::class,
];
```

By default, while casting value to money object, `currency` attribute will be used as a currency (or default application currency if there is no `currency` attribute in the model). If there is a need for custom attribute name from which currency is taken, such an attribute can be defined in model's `$casts` array, like this:

```
protected $casts = [
    'money' => \DeSmart\Larvel\Money\Casts\Money::class . ':my_custom_currency_attribute',
];
```

Casting class gets/sets money-like value from/to the model and also has a method for serializing `\Money\Money` objects to an array (when `toArray` or `toJson` methods are used on the model):

```
[
    // ...
    'money' => [
        'amount' => '10000',
        'currency' => 'PLN',
        'formatted' = '100,00 PLN',
        'float' = 100.0
    ],
]
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~17 days

Total

4

Last Release

1881d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a3c56cab812fc073277f1e127a12e0c6066565dc57bd3045484fcca1901021b?d=identicon)[gollum](/maintainers/gollum)

---

Top Contributors

[![golonix](https://avatars.githubusercontent.com/u/9950778?v=4)](https://github.com/golonix "golonix (22 commits)")

---

Tags

attributes-castinglaravellaravel-packagemoneylaravelmoneycastdesmart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[cknow/laravel-money

Laravel Money

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

PHP Laravel Money Package

74108.2k1](/packages/andriichuk-laracash)[wujunze/money-wrapper

MoneyPHP Wrapper

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

PHPackages © 2026

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