我一直在研究Laravel,但我还没有找到一些小问题的答案。
无论如何,我可以在模型中为列创建别名吗?
如果没有,我一直在为我的查询尝试一些变体,但似乎没有一个能给我想要的东西。
public function getEditHeader($adhID){
return View::make('adventures.editHeader')
->with('adventureheader', AdventureHeader::find($adhID)->select('adhID', 'adhTitle AS title', 'adhDescription AS description')->get())
->with('adventuretypes', AdventureType::orderBy('adtDescription')->lists('adtDescription', 'adtID'));
}
我已经尝试了许多变体,但我觉得我不明白我实际上在 Laravel 上尝试什么。我只是希望我的查询带有别名,因为我在表单的输入名称中没有我的表前缀。
使用 selectRaw
方法:
AdventureHeader::find($adhID)
->selectRaw('adhID, adhTitle AS title, adhDescription AS description')->get()
任何想要实现别名的人,请查看此链接:
拉拉维尔 4 雄辩的列别名