PHPackages                             lukeraymonddowning/mula - 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. lukeraymonddowning/mula

ActiveLibrary

lukeraymonddowning/mula
=======================

A Laravel package that makes working with money in a secure manner a cinch!

v1.3.0(3y ago)1538.6k↓29.2%6[1 PRs](https://github.com/lukeraymonddowning/mula/pulls)MITPHPPHP ^7.4|^8.0

Since Sep 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/lukeraymonddowning/mula)[ Packagist](https://packagist.org/packages/lukeraymonddowning/mula)[ Docs](https://github.com/lukeraymonddowning/mula)[ GitHub Sponsors](https://github.com/lukeraymonddowning)[ RSS](/packages/lukeraymonddowning-mula/feed)WikiDiscussions master Synced 1mo ago

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

Mula
====

[](#mula)

[![Latest Version on Packagist](https://camo.githubusercontent.com/be3bbfcb0a2b863822dde29589c088bc9848af4be317da0e1c4748cbc8b493b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c756b657261796d6f6e64646f776e696e672f6d756c612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lukeraymonddowning/mula)[![Mula PhpUnit Tests](https://github.com/lukeraymonddowning/mula/workflows/Mula%20PhpUnit%20Tests/badge.svg?branch=master)](https://github.com/lukeraymonddowning/mula/workflows/Mula%20PhpUnit%20Tests/badge.svg?branch=master)[![Quality Score](https://camo.githubusercontent.com/189b0d4f73eb2c0e7fde072f0e8a00d4d40a68f345a0a0722244074baa691689/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c756b657261796d6f6e64646f776e696e672f6d756c612e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/lukeraymonddowning/mula)

Mula is a [Laravel](https://laravel.com) package that makes it super easy to work with money in your applications. It uses [Money for PHP](http://moneyphp.org/en/stable/index.html) under the hood, but takes away all the complexity and provides all the pieces you need to be up and running with money in a matter of minutes.

Mula is also fully immutable, so you won't run in to issues changing values you really wish you hadn't. It also handles rounding and allocation, so you don't have to worry about any finances going missing.

TOC
---

[](#toc)

- [Installation](#installation)
- [Basic usage and API](#basic-usage-and-api)
    - [Create](#create)
    - [Parse](#parse)
    - [Display](#display)
    - [Display without currency](#display-without-currency)
    - [Currency](#currency)
    - [Value](#value)
    - [Add](#add)
    - [Subtract](#subtract)
    - [Multiply](#multiply-by)
    - [Divide](#divide-by)
    - [Modulus](#modulus)
    - [Has same currency](#has-same-currency-as)
    - [Equals](#equals)
    - [Is greater than](#is-greater-than)
    - [Is less than](#is-less-than)
    - [Splits and allocation](#split)
- [Storing money in a database](#storing-money-in-a-database)
- [Collection methods](#collection-methods)
    - [Financial sum](#financial-sum)

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

[](#installation)

You can install the package via composer:

```
composer require lukeraymonddowning/mula
```

You should publish the `mula.php` config file by running:

```
php artisan vendor:publish --provider="Lukeraymonddowning\Mula\MulaServiceProvider"
```

Basic usage and API
-------------------

[](#basic-usage-and-api)

We provide a `Mula` facade that allows you to easily create, parse and alter monetary values.

### Create

[](#create)

To manually create a new instance, use the `create` method.

```
Mula::create('12000', 'USD'); // $120.00
```

Note that when creating, we exclude any decimal point. Currency should be passed as an [ISO 4217 code](https://en.wikipedia.org/wiki/ISO_4217).

You may also exclude the currency, in which case `Mula` will use the default currency defined in the `mula.php` config file, or your `.env` file using the `MULA_CURRENCY` key.

Whilst we will use strings to pass values to the `create` method in the documentation, you are free to pass integer values instead.

### Parse

[](#parse)

More often than not, you'll want to parse existing monetary values rather than create new ones from scratch. You should use the `parse` method when handling user input or reading monetary values from a 3rd party API.

If you are using the `phpmoney` driver (which is the default), you have a few different drivers you can use for parsing money. You can set your desired driver in the `mula.php` config file, by altering the value of `mula.options.phpmoney.parser.default`.

We recommend using the default `aggregate` parser, but for the sake of clarity, we'll explain the difference between each one.

Whilst we will use strings to pass values to the `parse` method in the documentation, you are free to pass integers or decimal values instead.

#### Aggregate

[](#aggregate)

The `aggregate` parser (which is the default) is the most flexible driver available, and will attempt to parse monetary strings formatted in international or decimal. Here are a few examples:

```
Mula::parse('$120.99'); // $120.99

Mula::parse('120.99', 'USD'); // $120.99

Mula::parse('£120.99', 'USD'); // $120.99

Mula::parse('120', 'USD'); // $120.00
```

Note that in the third example, the money object is in USD, even though we parsed a value in GBP. That is because we passed a second parameter of `USD`. Passing in a currency will always override the given currency.

#### International

[](#international)

The `international` parser will parse full monetary string with currency, but will not parse decimal strings.

```
Mula::parse('$120.99'); // $120.99

Mula::parse('120.99'); // Exception
```

#### Decimal

[](#decimal)

The `decimal` parser will parse decimal values with the given currency (or the default currency), but will not parse monetary strings.

```
Mula::parse('120.99', 'USD'); // $120.99

Mula::parse('$120.99'); // Exception
```

### Display

[](#display)

To display money in the UI, you can use the `display` method. It accepts a single parameter, `includeCurrency`, which will either include or omit the currency symbol from the result.

```
Mula::create('12099', 'USD')->display(); // $120.99

Mula::create('12099', 'USD')->display(false); // 120.99
```

`Mula` also implements the `Stringable` interface, so you can output money directly in a blade view.

```
@php($money = Mula::create('12099', 'USD'))
{{ $money }}

{-- This will show as '$120.99' --}
```

### Display without currency

[](#display-without-currency)

As a syntactical nicety, you may use the `displayWithoutCurrency` method, which is just an alias for [`display(false)`](#display).

### Currency

[](#currency)

The `currency` method will return the [ISO 4217 code](https://en.wikipedia.org/wiki/ISO_4217) of the money object.

```
Mula::create('12099', 'USD')->currency(); // USD

Mula::create('12099', 'GBP')->currency(); // GBP
```

### Value

[](#value)

The `value` method will return the nonformatted value of the money object. You will rarely need to use this method, but `Mula` makes use of it for casting values to the database.

```
Mula::create('12099', 'USD')->value(); // 12099
```

### Add

[](#add)

The `add` method adds the provided money objects to the current money object and returns a new money object. You may pass any number of money objects as varadic parameters.

```
Mula::create('1500', 'USD')->add(Mula::create('1500', 'USD'))->display(); // $30.00

Mula::create('1500', 'USD')->add(Mula::create('1500', 'USD'), Mula::create('3000', 'USD'))->display(); // $60.00
```

### Subtract

[](#subtract)

The `subtract` method subtracts the provided money objects from the current money object and returns a new money object. You may pass any number of money objects as varadic parameters.

```
Mula::create('3000', 'USD')->subtract(Mula::create('1500', 'USD'))->display(); // $15.00

Mula::create('6000', 'USD')->subtract(Mula::create('1500', 'USD'), Mula::create('3000', 'USD'))->display(); // $15.00
```

### Multiply by

[](#multiply-by)

The `multiplyBy` method multiplies the money object by the given multiplier and returns a new money object.

```
Mula::create('5000', 'USD')->multiplyBy(2)->display(); // $100.00
```

### Divide by

[](#divide-by)

The `divideBy` method divides the money object by the given divisor and returns a new money object.

```
Mula::create('5000', 'USD')->divideBy(2)->display(); // $25.00
```

### Modulus

[](#modulus)

The `mod` method returns the remainder of money after being divided into another sum of money.

```
Mula::create('1000', 'USD')->mod(Mula::create('300', 'USD'))->display(); // $1.00
```

### Has same currency as

[](#has-same-currency-as)

To check if a money object has the same currency as other money objects, use the `hasSameCurrencyAs` method. It accepts a variable number of money objects as arguments. If any of the arguments have a different currency, the method will return `false`, otherwise it will return `true`.

```
Mula::create('1000', 'USD')->hasSameCurrencyAs(Mula::create('500', 'USD')); // TRUE

Mula::create('1000', 'USD')->hasSameCurrencyAs(Mula::create('500', 'GBP')); // FALSE

Mula::create('1000', 'USD')->hasSameCurrencyAs(Mula::create('500', 'USD'), Mula::create('3000', 'USD')); // TRUE

Mula::create('1000', 'USD')->hasSameCurrencyAs(Mula::create('500', 'USD'), Mula::create('3000', 'GBP')); // FALSE
```

### Equals

[](#equals)

To check if a money object is equal to other money objects, use the `equals` method. It accepts a variable number of money objects as arguments. If any of the arguments have a different amount, the method will return `false`, otherwise it will return `true`.

```
Mula::create('1000', 'USD')->equals(Mula::create('1000', 'USD')); // TRUE

Mula::create('1000', 'USD')->equals(Mula::create('500', 'USD')); // FALSE

Mula::create('1000', 'USD')->equals(Mula::create('1000', 'USD'), Mula::create('1000', 'USD')); // TRUE

Mula::create('1000', 'USD')->equals(Mula::create('1000', 'USD'), Mula::create('500', 'USD')); // FALSE
```

### Is greater than

[](#is-greater-than)

The `isGreaterThan` method checks if a money object is greater than all other money objects. It returns `true` if it is, or `false` if any of the money object provided are greater than or equal to it.

```
Mula::create('1000', 'USD')->isGreaterThan(Mula::create('999', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThan(Mula::create('1000', 'USD')); // FALSE

Mula::create('1000', 'USD')->isGreaterThan(Mula::create('1500', 'USD')); // FALSE

Mula::create('1000', 'USD')->isGreaterThan(Mula::create('999', 'USD'), Mula::create('800', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThan(Mula::create('1000', 'USD'), Mula::create('500', 'USD')); // FALSE
```

### Is greater than or equal to

[](#is-greater-than-or-equal-to)

The `isGreaterThanOrEqualTo` method checks if a money object is greater than or equal to all other money objects. It returns `true` if it is, or `false` if any of the money object provided are greater than it.

```
Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('999', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('1000', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('1500', 'USD')); // FALSE

Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('999', 'USD'), Mula::create('800', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('1000', 'USD'), Mula::create('500', 'USD')); // TRUE

Mula::create('1000', 'USD')->isGreaterThanOrEqualTo(Mula::create('1000', 'USD'), Mula::create('1500', 'USD')); // FALSE
```

### Is less than

[](#is-less-than)

The `isLessThan` method checks if a money object is less than all other money objects. It returns `true` if it is, or `false` if any of the money object provided are less than or equal to it.

```
Mula::create('1000', 'USD')->isLessThan(Mula::create('999', 'USD')); // FALSE

Mula::create('1000', 'USD')->isLessThan(Mula::create('1000', 'USD')); // TRUE

Mula::create('1000', 'USD')->isLessThan(Mula::create('1500', 'USD')); // TRUE

Mula::create('1000', 'USD')->isLessThan(Mula::create('1500', 'USD'), Mula::create('800', 'USD')); // FALSE

Mula::create('1000', 'USD')->isLessThan(Mula::create('1200', 'USD'), Mula::create('1500', 'USD')); // TRUE
```

### Is less than or equal to

[](#is-less-than-or-equal-to)

The `isLessThanOrEqualTo` method checks if a money object is less than or equal to all other money objects. It returns `true` if it is, or `false` if any of the money object provided are less than it.

```
Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('999', 'USD')); // FALSE

Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('1000', 'USD')); // TRUE

Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('1500', 'USD')); // TRUE

Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('999', 'USD'), Mula::create('800', 'USD')); // FALSE

Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('1000', 'USD'), Mula::create('500', 'USD')); // FALSE

Mula::create('1000', 'USD')->isLessThanOrEqualTo(Mula::create('1000', 'USD'), Mula::create('1500', 'USD')); // TRUE
```

### Split

[](#split)

Split is rather special. It allocates money based on the provided allocation. It can accept an `integer`, `array` or `Collection` and returns a `Collection` of `Money`.

If you want to split a money object as evenly as possible between a given number, pass an `integer`.

```
Mula::create('10000', 'USD')->split(3); // A Collection. The first item will have a value of $33.34 the second and third items will have a value of $33.33.
```

If you want to allocate money based on percentages, you may pass an `array` or `Collection` of numeric values. The values must add up to 100.

```
Mula::create('10000', 'USD')->split([30, 70]); // A Collection. The first item will have a value of $30.00 and the second item will have a value of $70.00.

Mula::create('10000', 'USD')->split(collect([30, 70])); // A Collection. The first item will have a value of $30.00 and the second item will have a value of $70.00.
```

Storing money in a database
---------------------------

[](#storing-money-in-a-database)

`Mula` makes it easy to store and retrieve money values from a database by providing a custom cast you can attach to your Eloquent models.

```
use Illuminate\Database\Eloquent\Model;
use Lukeraymonddowning\Mula\Casts\Mula;

class Product extends Model {

    protected $casts = [
        'price' => Mula::class
    ];

}
```

The column storing your monetary values in your database should be a string type. This prevents floating point errors and also allows `Mula` to store the currency along with the value.

If you'd prefer to store your amount and currency in two separate columns, which allows you more freedom when performing database queries, you can! Just let `Mula` know the amount column and currency column respectively in your `$casts` array.

```
use Illuminate\Database\Eloquent\Model;
use Lukeraymonddowning\Mula\Casts\Mula;

class Product extends Model {

    protected $casts = [
        'price' => Mula::class.':amount,currency'
    ];

}
```

Collection methods
------------------

[](#collection-methods)

`Mula` adds macros to Laravel Collections to make it easy to perform common monetary operations to a Collection of money objects.

### Financial sum

[](#financial-sum)

If you need to add together a `Collection` of money objects, you may use the `financialSum` method. It will return a new money object.

```
collect(Mula::create('1500', 'USD'), Mula::create('3000', 'USD'))->financialSum(); // A new money object with a value of $45.00.
```

### Testing

[](#testing)

`Mula` uses PhpUnit for unit tests. You can run the test suite from the terminal:

```
composer test
```

### Changelog

[](#changelog)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Luke Downing](https://github.com/lukeraymonddowning)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~214 days

Total

5

Last Release

1200d ago

PHP version history (2 changes)v1.0.0PHP ^7.4

1.2.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/139db346fa173a79481af05b0455e2e8ad7d2ab594c7f53bde3522a3dfeeaf25?d=identicon)[96downlu](/maintainers/96downlu)

---

Top Contributors

[![lukeraymonddowning](https://avatars.githubusercontent.com/u/12202279?v=4)](https://github.com/lukeraymonddowning "lukeraymonddowning (31 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

lukeraymonddowningmula

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukeraymonddowning-mula/health.svg)

```
[![Health](https://phpackages.com/badges/lukeraymonddowning-mula/health.svg)](https://phpackages.com/packages/lukeraymonddowning-mula)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[cknow/laravel-money

Laravel Money

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

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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