PHP code example of ibrand / laravel-currency-format

1. Go to this page and download the library: Download ibrand/laravel-currency-format library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ibrand / laravel-currency-format example snippets


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

> composer 



/*
 * 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');
    }
}