回答編集履歴
2
コード修正
test
CHANGED
@@ -38,19 +38,19 @@
|
|
38
38
|
|
39
39
|
->groupBy('date')
|
40
40
|
|
41
|
-
->map(function (
|
41
|
+
->map(function ($byDate) {
|
42
42
|
|
43
43
|
return $byDate
|
44
44
|
|
45
45
|
->groupBy('product_id')
|
46
46
|
|
47
|
-
->map(function (
|
47
|
+
->map(function ($byProductId) {
|
48
48
|
|
49
49
|
return $byProductId
|
50
50
|
|
51
51
|
->groupBy('type')
|
52
52
|
|
53
|
-
->map(function (
|
53
|
+
->map(function ($byType) {
|
54
54
|
|
55
55
|
return $byType->first()['count'];
|
56
56
|
|
1
groupByとmapを使った例を追記
test
CHANGED
@@ -21,3 +21,49 @@
|
|
21
21
|
});
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
最初に書いたやり方だとこんな感じ。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```php
|
32
|
+
|
33
|
+
$dictionary = App\HogeTable::whereDate('date', '>=', '2018-08-01')
|
34
|
+
|
35
|
+
->whereDate('date', '<=', '2018-08-31')
|
36
|
+
|
37
|
+
->get()
|
38
|
+
|
39
|
+
->groupBy('date')
|
40
|
+
|
41
|
+
->map(function (Collection $byDate) {
|
42
|
+
|
43
|
+
return $byDate
|
44
|
+
|
45
|
+
->groupBy('product_id')
|
46
|
+
|
47
|
+
->map(function (Collection $byProductId) {
|
48
|
+
|
49
|
+
return $byProductId
|
50
|
+
|
51
|
+
->groupBy('type')
|
52
|
+
|
53
|
+
->map(function (Collection $byType) {
|
54
|
+
|
55
|
+
return $byType->first()['count'];
|
56
|
+
|
57
|
+
})
|
58
|
+
|
59
|
+
->all();
|
60
|
+
|
61
|
+
})
|
62
|
+
|
63
|
+
->all();
|
64
|
+
|
65
|
+
})
|
66
|
+
|
67
|
+
->all();
|
68
|
+
|
69
|
+
```
|