PHP code example of desmart / laravel-money

1. Go to this page and download the library: Download desmart/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/ */

    

desmart / laravel-money example snippets


\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

// For example, in AppServiceProvider.php

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

// For example, in AppServiceProvider.php

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

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

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

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