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
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-16