Laravel雄辩 - distinct()和count()无法正常工作 [英] Laravel Eloquent - distinct() and count() not working properly together

查看:1095
本文介绍了Laravel雄辩 - distinct()和count()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图获得一个查询的不同的pid数,但返回的值是错误的。

So I'm trying to get the number of distinct pids on a query, but the returned value is wrong.

这是我试图做的: / p>

This is what I try to do:

$ad->getcodes()->groupby('pid')->distinct()->count()

什么返回值2,而应该返回的值应为1 。

what returns the value "2", while the value it should return, should be "1".

作为解决方法,我正在这样做:

As a workaround, I'm doing this:

count($ad->getcodes()->groupby('pid')->distinct()->get())

什么工作正常并返回1

有没有任何规则,count和distinct不能在同一个查询上?我发现解决方法很沉重,我想使原始查询工作:(

Is there any rule where count and distinct cannot be on the same query? I find the workaround kind of "heavy", I would like to make the original query work :(

推荐答案

$ad->getcodes()->distinct('pid')->count('pid');

这篇关于Laravel雄辩 - distinct()和count()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆