freshleafmedia/laravel-money-cast 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

freshleafmedia/laravel-money-cast

最新稳定版本:1.0.1

Composer 安装命令:

composer require freshleafmedia/laravel-money-cast

包简介

A Laravel attribute cast for Money values

README 文档

README

A Money cast for Laravel models

Overview

This library provides a Laravel Attribute Cast which serialises Money instances into strings suitable for database storage.

Installation

composer require freshleafmedia/laravel-money-cast

Usage

use Freshleafmedia\MoneyCast\MoneyCast;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    // ...

    protected $casts = [
        'cost' => MoneyCast::class,
    ];
    
    // ...
}

Saving

$model = new MyModel();
$model->cost = new \Money\Money('100', new \Money\Currency('GBP'));
$model->save(); // 'GBP100' is persisted to the database.

Retrieving

$cost = MyModel::first()->cost; // Money\Money

$cost->getAmount() // '100'
$cost->getCurrency()->getCode() // 'GBP'

Decimal Amounts

Note that due to the way moneyphp/money works amounts are in the smallest unit. For example GBP100 => £1.00, USD100 => $1.00, JPY100 => ¥100, etc.

See the Formatting section of the moneyphp docs for details

Tests

Unit tests can be run via composer test

License

See LICENSE

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-16