如何在 Laravel 5.8 中执行 groupBy?

How to perform a groupBy in Laravel 5.8?

我有一个 table 有 41 行

我做到了

public function types()
{
    return DB::table('graphs')->groupBy('title')->get();
}

我不断得到

有人可以帮忙吗?

我希望得到这 3 个

['MBN_PRIVATE','MBN_GUEST','SPWIFI'];

在 MySql 严格模式下,您不能 return 在 group by 查询中使用非聚合字段。 如果您只需要标题的值,请添加 select 或 pluck 方法

public function types()
{
    return DB::table('graphs')->groupBy('title')->pluck('title')->toArray();
}

尝试使用 orderBy() 而不是 groupBy()。

public function types()
{
    return DB::table('graphs')->orderBy('title')->get();
}