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

标签 php laravel laravel-5 eloquent

我有一个由 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/

相关文章:

Laravel 在包中注册种子

ajax - Laravel 和 Ajax 返回数组响应不解析

php - 使用 PHP 更新数据库中现有库存水平和价格的数组值

javascript - 如何执行这个数组(jQuery Ajax)?

laravel - 使用 Laravel/Dusk 在 headless chrome 中下载文件

php - Laravel 5.5 Eloquent 没有在搜索字符串周围加上引号

javascript - 如何从 URL : http://www. 获取 "foo"loremipsum.com/mysite.html#foo

php - 如何检查我的 paypal 自适应支付是否正常工作?

authentication - Laravel 4 中的角色特定登录

laravel - 如何在自定义请求类中获取模型 ID