如何将groupby()和sortby()作为一个Laravel集合?

时间:2017-08-11 14:18:36

标签: sorting laravel-5 methods collections

这是我的收藏品的结构

  0 => array:13 [▼
    "id" => 173
    "campaign_id" => "STM1234"
    "product_id" => "STM1234"
    "group" => "24"
    "version" => "1"
    "created_at" => "2017-08-04 14:02:33"
    "updated_at" => "2017-08-04 14:02:33"
    "groups" => array:5 [▼
      "id" => 24
      "campaign_id" => "STM1234"
      "group_name" => "default"
      "updated_at" => null

我正在尝试对此系列进行分组和订购。

$ groups = $ products-> groupBy(' groups.group_name') - > sortBy(' groups.id');

然而,分组工作无效

array:2 [▼
  "group2" => array:3 [▶]
  "default" => array:8 [▶]
]

默认的id为零,所以首先应该做些什么才能在列表中首先获得id为0的组?

0 个答案:

没有答案