akaunting / laravel-money by denisdulici

Currency formatting and conversion package for Laravel
2,955,854
669
17
Package Data
Maintainer Username: denisdulici
Maintainer Contact: info@akaunting.com (Denis Duliçi)
Package Create Date: 2017-11-26
Package Last Update: 2024-03-29
Home Page: https://akaunting.com
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 15:14:16
Package Statistics
Total Downloads: 2,955,854
Monthly Downloads: 95,152
Daily Downloads: 4,032
Total Stars: 669
Total Watchers: 17
Total Forks: 94
Total Open Issues: 4

Currency formatting and conversion package for Laravel

Downloads Tests StyleCI Quality License

This package intends to provide tools for formatting and conversion monetary values in an easy, yet powerful way for Laravel projects.

Why not use the moneyphp package?

Because moneyphp uses the intl extension for number formatting. intl extension isn't present by default on PHP installs and can give different results in different servers.

Getting Started

1. Install

Run the following command:

composer require akaunting/laravel-money

2. Register (for Laravel < 5.5)

Register the service provider in config/app.php

Akaunting\Money\Provider::class,

3. Publish

Publish config file.

php artisan vendor:publish --tag=money

4. Configure

You can change the currencies information of your app from config/money.php file

Usage

use Akaunting\Money\Currency;
use Akaunting\Money\Money;

echo Money::USD(500); // '$5.00' unconverted
echo new Money(500, new Currency('USD')); // '$5.00' unconverted
echo Money::USD(500, true); // '$500.00' converted
echo new Money(500, new Currency('USD'), true); // '$500.00' converted

Advanced

$m1 = Money::USD(500);
$m2 = Money::EUR(500);

$m1->getCurrency();
$m1->isSameCurrency($m2);
$m1->compare($m2);
$m1->equals($m2);
$m1->greaterThan($m2);
$m1->greaterThanOrEqual($m2);
$m1->lessThan($m2);
$m1->lessThanOrEqual($m2);
$m1->convert(Currency::GBP, 3.5);
$m1->add($m2);
$m1->subtract($m2);
$m1->multiply(2);
$m1->divide(2);
$m1->allocate([1, 1, 1]);
$m1->isZero();
$m1->isPositive();
$m1->isNegative();
$m1->format();

Helpers

money(500, 'USD')
currency('USD')

Blade Directives

@money(500, 'USD')
@currency('USD')

Changelog

Please see Releases for more information what has changed recently.

Contributing

Pull requests are more than welcome. You must follow the PSR coding standards.

Security

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

Credits

License

The MIT License (MIT). Please see LICENSE for more information.