PHP code example of cyrtolat / laravel-money

1. Go to this page and download the library: Download cyrtolat/laravel-money library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cyrtolat / laravel-money example snippets

)

[comment]: <> ('locale' => 'en_US')

[comment]: <> (
)

[comment]: <> ('storage' => \Cyrtolat\Money\Storages\IsoCurrencyStorage::class)

[comment]: <> (
)

[comment]: <> ('serializer' => \Cyrtolat\Money\Serializers\MajorMoneySerializer::class)

[comment]: <> (
)

[comment]: <> ('formatter' => \Cyrtolat\Money\Formatters\DecimalMoneyFormatter::class)

[comment]: <> (
)

[comment]: <> (use \Cyrtolat\Money\Facades\Money;)

[comment]: <> (# указание значения в "минорном" и "мажорном" стилях)

[comment]: <> ($money = Money::of&#40;150.23, 'RUB'&#41;; // 150.23 RUB)

[comment]: <> ($money = Money::ofMinor&#40;15023, 'RUB'&#41;; // 150.23 RUB)

[comment]: <> (# также можно передавать и объект Currency вместо кода)

[comment]: <> ($currency = Money::getCurrencyOf&#40;'RUB'&#41;;)

[comment]: <> ($money = Money::of&#40;150.23, $currency&#41;;)

[comment]: <> ($money = Money::ofMinor&#40;15023, $currency&#41;;)

[comment]: <> (
)

[comment]: <> (use \Cyrtolat\Money\Facades\Money;)

[comment]: <> ($money_1 = Money::of&#40;150.23, 'RUB'&#41;; // 150.23 RUB)

[comment]: <> ($money_2 = Money::of&#40;320.88, 'RUB'&#41;; // 320.88 RUB)

[comment]: <> ($money = $money_1->plus&#40;$money_2&#41;; // $money_1 + $money_2)

[comment]: <> ($money = $money_1->minus&#40;$money_2&#41;; // $money_1 - $money_2)

[comment]: <> ($money = $money_1->multiplyBy&#40;2.3&#41;; // $money_1 * 2.3)

[comment]: <> ($money = $money_1->divideBy&#40;4&#41;; // $money_1 / 4)

[comment]: <> ($money = $money_1->round&#40;&#41;; // 150.00 RUB)

[comment]: <> ($bool = $money_1->gt&#40;$money_2&#41;; // $money_1 > $money_2)

[comment]: <> ($bool = $money_1->gte&#40;$money_2&#41;; // $money_1 >= $money_2)

[comment]: <> ($bool = $money_1->lt&#40;$money_2&#41;; // $money_1 < $money_2)

[comment]: <> ($bool = $money_1->lte&#40;$money_2&#41;; // $money_1 <= $money_2)

[comment]: <> ($bool = $money_1->equals&#40;$money_2&#41;; // $money_1 == $money_2)

[comment]: <> ($bool = $money_1->hasSameAmount&#40;$money_2&#41;; // false)

[comment]: <> ($bool = $money_1->hasSameCurrency&#40;$money_2&#41;; // true)

[comment]: <> (
)

[comment]: <> (use \Cyrtolat\Money\Facades\Money;)

[comment]: <> ($money = Money::of&#40;150.23, 'RUB'&#41;;)

[comment]: <> (# I have: 150.23 RUB)

[comment]: <> (echo "I have: " . $money->render&#40;&#41;;)

[comment]: <> (echo "I have: " . $money;)

[comment]: <> (
bash

php artisan vendor:publish --provider="Cyrtolat\Money\Providers\MoneyServiceProvider"