PHP code example of origami / money
1. Go to this page and download the library: Download origami/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/ */
origami / money example snippets
$money = new Origami\Money\Money(100, 'GBP') // £1
$money = new Origami\Money\Money(50000, 'USD') // $500
$money = Origami\Money\Money::make(1000000, 'USD') // $10,000
$currency = new Money\Currency('GBP');
$base = new Money\Money(100, $currency);
$money = new Origami\Money\Money($base, $currency);
Origami\Money\Money::instance(new Money\Money(500, new Money\Currency('GBP')));
$money = new Origami\Money\Money(500, 'GBP'); // £5
$another = $money->copy();
$andAnother = $money->clone(); // Alias for above
$money = new Origami\Money\Money(500, 'GBP'); // £5
$base = $money->asBase(); // Money\Money
$gbp = new Origami\Money\Money(500, 'GBP'); // £5
$usd = new Origami\Money\Money(500, 'USD'); // $5
$money->isSameCurrency(); // false
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = Origami\Money\Money::make(500, 'GBP'); // £5
$money->equals(); // true
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(600, 'GBP'); // £6
$second->greaterThan($first); // true
$second->gt($first); // Alias for above
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(500, 'GBP'); // £5
$second->greaterThanOrEqual($first); // true
$second->gte($first); // Alias for above
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(600, 'GBP'); // £6
$second->lessThan($first); // false
$second->lt($first); // Alias for above
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(500, 'GBP'); // £5
$second->lessThanOrEqual($first); // true
$second->lte($first); // Alias for above
$first = new Origami\Money\Money(500, 'GBP'); // £5
$zero = new Origami\Money\Money(0, 'GBP'); // £0
$first->isZero(); // false
$zero->isZero(); // true
$first = new Origami\Money\Money(500, 'GBP'); // £5
$first->isPositive(); // true
$first = new Origami\Money\Money(500, 'GBP'); // £5
$first->isNegative(); // false
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(1000, 'GBP'); // £10
$first->percentageOf($second); // 50
$first = new Origami\Money\Money(1000, 'GBP'); // £10
$second = new Origami\Money\Money(500, 'GBP'); // £5
$first->percentageOf($second, false); // 100
$money = new Origami\Money\Money(500, 'GBP'); // £5
$amount = $money->getAmount(); // 500
$money = new Origami\Money\Money(500, 'GBP'); // £5
$currency = $money->getCurrency(); // `Money\Currency('GBP')`
$money = new Origami\Money\Money(500, 'GBP'); // £5
$currency = $money->getCurrencyCode(); // "GBP"
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(400, 'GBP'); // £4
$first->add($second); // `Origami\Money(900, 'GBP')`
$first = new Origami\Money\Money(500, 'GBP'); // £5
$second = new Origami\Money\Money(400, 'GBP'); // £4
$first->add($second); // `Origami\Money(100, 'GBP')`
$money = new Origami\Money\Money(500, 'GBP'); // £5
$money->multiply(2); // `Origami\Money(1000, 'GBP')`
$money = new Origami\Money\Money(500, 'GBP'); // £5
$money->divide(2); // `Origami\Money(250, 'GBP')`
$money = new Origami\Money\Money(830, 'GBP'); // £8.30
$divisor = new Origami\Money\Money(300, 'GBP'); // £3.00
$money->add($divisor); // `Origami\Money(230, 'GBP')`
$three = new Origami\Money\Money(300, 'GBP'); // £3
$six = new Origami\Money\Money(600, 'GBP'); // £6
$three->ratioOf($six); // 0.5
$money = new Origami\Money\Money(-500, 'GBP'); // -£5
$money->absolute(); // `Origami\Money(500, 'GBP')`
$money = new Origami\Money\Money(500, 'GBP'); // £5
$money->negative(); // `Origami\Money(-500, 'GBP')`
$money = new Origami\Money\Money(500, 'GBP');
$money->format(); // Outputs: £5.00
(string) $money; // Outputs: £5.00 (uses `__toString()`)
app('origami-money.formatter')->format($money) // Outputs: £5.00
$money = new Origami\Money\Money(500, 'GBP');
$money->formatNeat(); // Outputs: £5
app('origami-money.formatter')->formatNeat($money) // Outputs: £5
$money = new Origami\Money\Money(500, 'GBP');
$money->formatDecimal(); // Outputs: 5.00
$money->toDecimal(); // Alias for above
app('origami-money.formatter')->formatDecimal($money) // Outputs: 5.00
@money($money)
// same as `$money->format()`
@moneyNeat($money)
// same as `$money->formatNeat()`
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Origami\Money\Casts\Money;
class Invoice extends Model
{
protected $fillable = ['description','total', 'currency'];
protected $casts = ['total' => Money::class];
}
$currency = 'USD';
$invoice = new Invoice(['currency' => $currency, 'total' => new Origami\Money\Money(70000, $currency)]);
$input = [
'currency' => 'GBP',
'total' => '10.50',
];
$invoice = new Invoice($input);
bash
php artisan vendor:publish --tag="money-config"