别名列的名字,我有一个名为口才雄辩的模型:如何雄辩
Products::where("actice", "=", true)->get()->toArray();
现在我想补充加入语句吧,我已经定义了一个scopeQuery有:
public function scopeJoinWithTags($query)
{
return $query->leftJoin("tags", "tags.id", "=", "products.tag_id");
}
那么,我们的主查询更改为:
Products::where("actice", "=", true)->joinWithTags->get()->toArray();
我得到的是好的,这是我所期望的,但我想改名字标记表的属性tag_name,我应该怎么做?我的意思是,我在查询某说:
tags.name AS tag_name
所以最后的结果数组中我做的:
$result[$i]['tag_name'];
虽然现在我要:
$result[$i]['name'];
可能重复[http://stackoverflow.com/questions/一个更清洁的方式17174837/laravel-4-eloquent-column-alias](http://stackoverflow.com/questions/17174837/laravel-4-eloquent-column-alias) – itachi