nevadskiy/laravel-money

此包为Laravel应用程序提供货币和货币功能。

0.3.0 2023-06-14 21:24 UTC

This package is auto-updated.

Last update: 2024-09-15 00:16:42 UTC


README

💰 此包为Laravel应用程序提供货币和货币功能。

安装

您可以通过composer安装此包

composer require nevadskiy/laravel-money

文档

在模型中使用money cast

任何字段都可以转换为Money实例。要使其可转换,请将以下代码添加到您的模型中

use Nevadskiy\Money\Casts\AsMoney;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'cost' => AsMoney::class.':UAH',
];

具有动态货币的Money cast

Schema::create('products', function (Blueprint $table) {
    $table->bigInteger('cost')->unsigned();
    $table->string('currency', 3);
});
use Nevadskiy\Money\Casts\AsMoney;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'cost' => AsMoney::class.':[currency]',
];

待办事项列表

  • 使用Symfony\Polyfill\Intl\Icu\Currencies作为默认注册表