我有uisng laravel 4
我有这样的数据:2016-02-12 18:32:19
我有这样的查询
echo $result = SourceManagement::get(array('id', 'created_at', DB::raw("date_format(from_unixtime(created_at), '%Y') as created_at")));
// print_r($result);
为什么输出是这样的:
[
{
"id":1,
"created_at":null
},
{
"id":3,
"created_at":null
},
{
"id":4,
"created_at":null
},
{
"id":7,
"created_at":null
},
{
"id":8,
"created_at":null
},
{
"id":9,
"created_at":null
},
{
"id":10,
"created_at":null
},
{
"id":11,
"created_at":null
},
{
"id":12,
"created_at":null
},
{
"id":13,
"created_at":null
},
{
"id":14,
"created_at":null
}
]
答案 0 :(得分:1)
像这样更新你的查询,这可能会解决你的问题,根据我的理解你正在覆盖默认的列名,这就是为什么你得到null,我测试下面的查询,它工作正常。
$result = SourceManagement::get(array('id', 'created_at', DB::raw("date_format(created_at, '%Y') as created_at_custom")));