【问题标题】:Is it possible to format a displayed data in Voyager?是否可以在 Voyager 中格式化显示的数据?
【发布时间】:2018-07-09 14:48:57
【问题描述】:

我是Voyager 的新手,我想将一些数字格式化为货币格式。通常,我会这样做

//In a blade file {{ $number_format($product->price, 0, ',', '.') }}

如果我想在 BREAD 视图中格式化显示的数据,我的 JSON 字符串应该如何实现我的目的?

【问题讨论】:

    标签: php laravel-5 voyager


    【解决方案1】:

    您可以使用Eloquent accessors

    在您的实例中,这可能如下所示:

    <?php
    
        namespace App;
    
        use Illuminate\Database\Eloquent\Model;
    
        class Product extends Model
        {
            /**
             * Get the product's price.
             *
             * @param  string  $value
             * @return string
             */
            public function getPriceAttribute($value)
            {
                return number_format($value, 0, ',', '.');
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      相关资源
      最近更新 更多