gpt4 book ai didi

php - Laravel 5.5 Eloquent 在多于 1 列的情况下变得不同

转载 作者:行者123 更新时间:2023-12-02 06:50:21 25 4
gpt4 key购买 nike

我有一个由 id 索引的表,还有一个列描述。

我想以填充 radio 组的形式使用它。

我的问题是如果我尝试

$colours = Colours::where('manufacturer_id',"=",$man)->select('id','description')->orderBy('description')->groupBy('description')->get();

我得到

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'cl24-ids.colours.manufacturer_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select description, manufacturer_id from colours where manufacturer_id = 1 group by description)



请问有什么想法还是我应该只使用非 Eloquent 解决方案?

最佳答案

distinct 方法允许您获取查询以返回不同的结果:

$users = DB::table('users')->distinct()->get();
获取唯一行
$categories = Machine::distinct('category')->pluck('category','antoher');

关于php - Laravel 5.5 Eloquent 在多于 1 列的情况下变得不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46422496/

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