我一直在研究 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()
关于php - Laravel PHP 模型上的别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27390309/