1. Go to this page and download the library: Download elegantly/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/ */
elegantly / laravel-money example snippets
return [
'default_currency' => 'USD',
];
Schema::create('invoices', function (Blueprint $table) {
$table->id();
$table->bigInteger('amount'); // e.g., 1000 = $10.00
$table->string('currency', 3); // ISO 4217 code
$table->timestamps();
});
use Elegantly\Money\MoneyCast;
use Brick\Money\Money;
/**
* @property Money $amount
* @property string $currency
*/
class Invoice extends Model
{
protected function casts(): array
{
return [
'amount' => MoneyCast::of('currency'),
];
}
}
use Elegantly\Money\MoneyCast;
use Brick\Money\Money;
/**
* @property Money $amount
* @property Money $cost
*/
class Invoice extends Model
{
protected function casts(): array
{
return [
'cost' => MoneyCast::of('EUR'),
'price' => MoneyCast::of('USD'),
];
}
}