laravel - 在 laravel 中使用访问器的问题
问题描述
我需要使用两种不同类型的 created_at 字段
public function getCreatedAtAttribute($value)
{
$time = new \Verta($value);
return $time->formatDifference();
}
这是我的代码,我也需要使用默认 created_at 值
请帮我
解决方案
created_at_diff
您可以尝试为您的特殊格式创建另一个具有不同名称(也许)的访问器:
public function getCreatedAtDiff()
{
return (new \Verta($this->attributes['created_at']))->formatDifference();
// or $this->created_at instead of $this->attributes['created_at']
}
然后您可以通过$model->created_at_diff
.
推荐阅读
- python - 使用 django-extra-views 的内联表单集的问题
- flutter - 如何在小部件树中使用此函数的值?
- sql-server - T-SQL 中的原始 XML 反序列化
- python - 每月数据汇总
- c++ - 如果没有错误,为什么GL函数调用-1返回的位置?
- spring-boot - 在 Spring Boot 运行时将 Jasper Sub Report 作为参数传递
- node.js - Node.js 拆分文件行
- google-apps-script - 如何将范围从一个 Google 工作表移动到另一个工作表/标签中的下一个空白行
- excel - 彭博 =baddperiods() 和 =bdh() 问题
- java - 如何使用 mockito-inline 模拟子线程的 run() 方法