【发布时间】:2016-12-22 17:24:48
【问题描述】:
我需要在加载时向 eloquent 模型添加自定义字段。处理结果收集时,带有附加的方法不起作用
protected $appends = ['formatted_date'];
public function getFormattedDateAttribute()
{
return $this->date->format('D-m-y');
}
当我尝试 $collection->pluck($key, 'formatted_date') 时,出现错误 ** Unknown column 'formatted_date' in 'field list'**
【问题讨论】:
-
已解决,问题是要收集的源数据,如果使用 $collection = Table::whereBetween('date',[$from, $to]) ,只需添加 get() 即可
标签: laravel eloquent laravel-5.2