【发布时间】:2019-05-20 03:48:44
【问题描述】:
我想要数据库表中的不同名称。该表包含列 ID 和名称。
我试过了$diff=Crud::distinct('name')->get(); $diff=Crud::distinct()->get();
他们都没有工作。他们返回的结果是重复的。这里 Crud 是我雄辩的模型。
但是当我使用时
$cnt=Crud::distinct()->count('name'); //returns the correct count
和
$u=Crud::all();
$diff=$u->unique('name'); //returns the distinct names
为什么在我使用 distinct 时会返回重复值?我想要使用 distinct 来区分名称。
谢谢。
【问题讨论】:
-
Crud 是你模型的名字吗?
-
是的! Crud 是我的模型的名称。
标签: laravel-5 eloquent distinct