回答編集履歴

5

Fix

2021/10/14 04:30

投稿

kai0310
kai0310

スコア2076

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ])->withCount(['products' => function ($query) {
8
8
 
9
- $query->groupBy('sales_product.product_id');
9
+ $query->groupBy('sales_product.product_id');
10
10
 
11
11
  }])->get();
12
12
 

4

Fix

2021/10/14 04:30

投稿

kai0310
kai0310

スコア2076

test CHANGED
@@ -1,21 +1,17 @@
1
1
  ```PHP
2
2
 
3
+ Sales::whereBetween('date', [
3
4
 
5
+ $startDate, $endDate
4
6
 
5
- $startDate = Carbon::createFromFormat('Y-m-d', now())->startOfDay();
7
+ ])->withCount(['products' => function ($query) {
6
8
 
7
- $endDate = Carbon::createFromFormat('Y-m-d', now())->endOfDay();
9
+ $query->groupBy('sales_product.product_id');
10
+
11
+ }])->get();
8
12
 
9
13
 
10
14
 
11
15
 
12
16
 
13
- Sales::whereBetween('date', [
14
-
15
- $startDate, $endDate
16
-
17
- ])->products()->groupBy('sales_product.product_id')->get();
18
-
19
-
20
-
21
17
  ```

3

Fix

2021/10/14 04:28

投稿

kai0310
kai0310

スコア2076

test CHANGED
@@ -1,6 +1,20 @@
1
1
  ```PHP
2
2
 
3
+
4
+
5
+ $startDate = Carbon::createFromFormat('Y-m-d', now())->startOfDay();
6
+
7
+ $endDate = Carbon::createFromFormat('Y-m-d', now())->endOfDay();
8
+
9
+
10
+
11
+
12
+
13
+ Sales::whereBetween('date', [
14
+
15
+ $startDate, $endDate
16
+
3
- Sales::whereBetween('date', '2020-xx-xx xx:xx:xx', '2021-xx-xx xx:xx:xx')->products()->groupBy('sales_product.product_id')->get();
17
+ ])->products()->groupBy('sales_product.product_id')->get();
4
18
 
5
19
 
6
20
 

2

Fix

2021/10/14 03:23

投稿

kai0310
kai0310

スコア2076

test CHANGED
@@ -1,8 +1,6 @@
1
1
  ```PHP
2
2
 
3
-
4
-
5
- Sales::find(id)->products()->whereDate('sales_product.created_at', now())->groupBy('sales_product.product_id')->get();
3
+ Sales::whereBetween('date', '2020-xx-xx xx:xx:xx', '2021-xx-xx xx:xx:xx')->products()->groupBy('sales_product.product_id')->get();
6
4
 
7
5
 
8
6
 

1

Fix

2021/10/14 02:52

投稿

kai0310
kai0310

スコア2076

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- Sales::find(id)->products()->whereDate('sales_product.created_at', now())->count();
5
+ Sales::find(id)->products()->whereDate('sales_product.created_at', now())->groupBy('sales_product.product_id')->get();
6
6
 
7
7
 
8
8