PHPackages                             ibrand/laravel-currency-format - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. ibrand/laravel-currency-format

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

ibrand/laravel-currency-format
==============================

iBrand coterie server.

v1.0.0(7y ago)43.5kMITPHPPHP &gt;=7.0CI failing

Since Dec 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/guojiangclub/laravel-currency-format)[ Packagist](https://packagist.org/packages/ibrand/laravel-currency-format)[ RSS](/packages/ibrand-laravel-currency-format/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

\###laravel-currency-format

Laravel 贴合实际需求同时方便扩展的数字，金额格式化组件

基于业务需求，需要把数字，金额格式化以方便前端展示，`laravel Eloquent`官方提供了修改器，如将以`分`为单位的`amount`字段换算成`元`：

```
public function getAmountAttribute()
{
	return number_format($this->value, 2, '.', '');
}
```

### Featrue

[](#featrue)

1. 自定义需要转换的字段
2. `Trait`即引即用
3. `FormatContract`方便扩展开发
4. 支持`toArray`数组化

### 安装

[](#安装)

> ```
> composer require ibrand/laravel-currency-format
> ```

### 使用

[](#使用)

1. 定义`Eloquent Model`模型
2. 引用 格式化`Trait`模型： `use iBrand\Currency\Format\HasFormatAttributesTrait`
3. 自定义格式化字段：`protected $format_attributes`

> 就是这么简单

```
