Laravel Money
Published on by Paul Redmond
Laravel Money is a composer package by Ricardo Gobbo de Souza for working with and formatting money in Laravel projects.
Laravel money uses the moneyphp/money PHP package under the hood and gives you a bunch of helpers:
use Cknow\Money\Money; echo Money::USD(500); // $5.00
This package includes a ton of advanced features for doing money operations, comparisons, aggregations, formatting, and parsing:
// Basic operationsMoney::USD(500)->add(Money::USD(500)); // $10.00Money::USD(500)->subtract(Money::USD(400)); // $1.00 // AggregationMoney::min(Money::USD(100), Money::USD(200), Money::USD(300)); // Money::USD(100) // FormattersMoney::USD(500)->format(); // $5.00 // ParsersMoney::parse('$1.00'); // Money::USD(100)
You can also create a custom formatter for your specific use-case:
Money::USD(500)->formatByFormatter(new MyFormatter());
Be sure to check out the advanced usage and included helper functions in the project’s README file. Also, check out the Money PHP documentation for complete details of what this package is capable of doing.
You can learn more about this package and check out the source code on GitHub at cknow/laravel-money.