別名列的名字,我有一個名爲口才雄辯的模型:如何雄辯
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