1. Go to this page and download the library: Download red-jasmine/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/ */
use Illuminate\Database\Eloquent\Model;
use Money\Money;
use RedJasmine\Money\Casts\MoneyCast;
class Product extends Model
{
protected $casts = [
'price' => MoneyCast::class,
];
}
use Money\Money;
use RedJasmine\Money\Casts\MoneyCast;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;
class ProductData extends Data
{
public function __construct(
public string $name,
#[WithCast(MoneyCast::class)]
public ?Money $price = null,
) {
}
}
use Money\Currency;
use Money\Money;
// 使用积分
$points = new Money(1000, new Currency('POINTS'));
// 使用游戏金币
$gold = new Money(500, new Currency('GOLD'));
// 使用代金券
$voucher = new Money(5000, new Currency('VOUCHER')); // 50.00