与groupby一样
我有一个带有以下记录的用户表:
从上面的记录中,我只想获取具有类似名称的用户。
我的预期结果是使用户具有类似名称的用户,如下图:
所以,这就是我尝试的:
$users = User::groupBy('name')->having(DB::raw('count(*)'), ">", "1")->select('name')->get();
dd($clients);
但是这是我得到的结果:
I have a users table with the following records:
From the above records, i want to fetch only users with like names.
My expected result is to get users with like names as seen in the screenshot below:
So, this is what I've tried:
$users = User::groupBy('name')->having(DB::raw('count(*)'), ">", "1")->select('name')->get();
dd($clients);
But this is the result I was getting:
I want to able to get the users with like names.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将返回所有具有包含字符串$ searchTerm的名称或电子邮件的记录。
因此,就您而言,您可能还需要添加GroupBy语句。
您可以在链接
This will return all records that have a name or email that contains the string in $searchTerm.
So in your case, you might need to add a groupBy statement too.
You can find more details in this link
我确实认为在您的情况下这应该有效:
upp:
I do think this should work in your case:
UPD: