承接 ibrand/laravel-currency-format 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ibrand/laravel-currency-format

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ibrand/laravel-currency-format

包简介

iBrand coterie server.

README 文档

README

###laravel-currency-format

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

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

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

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

就是这么简单

<?php

/*
 * This file is part of ibrand/laravel-currency-formatter.
 *
 * (c) iBrand <https://www.ibrand.cc>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace iBrand\Currency\Format;

use iBrand\Currency\Format\HasFormatAttributesTrait;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFormatAttributesTrait;//引用格式化Trait

    protected $guarded = ['id'];

    protected $format_attributes = ['total', 'items_total'];//自定义需要格式化的字段,就是这么简单

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
      
      	$this->setTable(config('ibrand.app.database.prefix', 'ibrand_').'order');
    }
}

如访问格式化total属性,$order->display_total即可。

统计信息

  • 总下载量: 3.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-27