回答編集履歴

2

修正

2021/03/02 04:22

投稿

phper.k
phper.k

スコア3923

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  ->when(count($words), function ($query) use ($words) {
36
36
 
37
- $query->where(function($query){
37
+ $query->where(function($query) use ($words) {
38
38
 
39
39
  foreach ($words as $word) {
40
40
 

1

修正

2021/03/02 04:22

投稿

phper.k
phper.k

スコア3923

test CHANGED
@@ -34,17 +34,21 @@
34
34
 
35
35
  ->when(count($words), function ($query) use ($words) {
36
36
 
37
- foreach ($words as $word) {
37
+ $query->where(function($query){
38
38
 
39
- $query->where('title', 'like', '%' . $word . '%')
39
+ foreach ($words as $word) {
40
40
 
41
- ->orWhere('target_site', 'like', '%' . $word . '%')
41
+ $query->where('title', 'like', '%' . $word . '%')
42
42
 
43
- ->orWhere('content', 'like', '%' . $word . '%')
43
+ ->orWhere('target_site', 'like', '%' . $word . '%')
44
44
 
45
- ->orWhere('created_at', 'like', '%' . $word . '%');
45
+ ->orWhere('content', 'like', '%' . $word . '%')
46
46
 
47
+ ->orWhere('created_at', 'like', '%' . $word . '%');
48
+
47
- }
49
+ }
50
+
51
+ })
48
52
 
49
53
  })
50
54