我有一个由 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
fromcolours
wheremanufacturer_id
= 1 group bydescription
)
请问有什么想法还是我应该只使用非 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/