php - 是否可以在 Voyager 中格式化显示的数据?
问题描述
我是Voyager的新手,我想将一些数字格式化为货币格式。通常,我会这样做
//In a blade file
{{ $number_format($product->price, 0, ',', '.') }}
如果我想在 BREAD 视图中格式化显示的数据,我的 JSON 字符串应该如何实现我的目的?
解决方案
您可以使用Eloquent 访问器。
在您的实例中,这可能如下所示:
<?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, ',', '.');
}
}
推荐阅读
- java - 为私有静态内部类注入bean
- wpf - 如果 HorizontalContentAlignment="Right",WPF TexBox 不会关注鼠标单击
- kubernetes - 同时运行两个 Kubernetes 仪表板
- assembly - 如何在 2 列中显示交替的文本行?
- sql-server - 两个表的多内连接
- r - 无法获取带有边界框的谷歌卫星图像
- reactjs - 使用 jest 和酶进行测试时,在单击事件中不调用模拟函数
- typescript - 如何推断对象属性的类型
- android - BottomSheetDialogFragment 通过 android 软键(返回、主页)进行动画处理
- email - BUILD_LOG 电子邮件输出不包括控制台日志中的错误文本