teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

Fix

2021/10/14 04:30

投稿

kai0310
kai0310

スコア2076

answer CHANGED
@@ -2,7 +2,7 @@
2
2
  Sales::whereBetween('date', [
3
3
  $startDate, $endDate
4
4
  ])->withCount(['products' => function ($query) {
5
- $query->groupBy('sales_product.product_id');
5
+ $query->groupBy('sales_product.product_id');
6
6
  }])->get();
7
7
 
8
8
 

4

Fix

2021/10/14 04:30

投稿

kai0310
kai0310

スコア2076

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

3

Fix

2021/10/14 04:28

投稿

kai0310
kai0310

スコア2076

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

2

Fix

2021/10/14 03:23

投稿

kai0310
kai0310

スコア2076

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

1

Fix

2021/10/14 02:52

投稿

kai0310
kai0310

スコア2076

answer CHANGED
@@ -1,5 +1,5 @@
1
1
  ```PHP
2
2
 
3
- Sales::find(id)->products()->whereDate('sales_product.created_at', now())->count();
3
+ Sales::find(id)->products()->whereDate('sales_product.created_at', now())->groupBy('sales_product.product_id')->get();
4
4
 
5
5
  ```