gpt4 book ai didi

php - Laravel PHP 模型上的别名?

转载 作者:行者123 更新时间:2023-11-29 12:31:43 30 4
gpt4 key购买 nike

我一直在研究 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com