回答編集履歴

2

タグのテーブル名を質問に合わせてtag(単数形)にしました。(手元で動作確認するときにlaravelの習慣にあわせて複数形のtagsにしてしまっていたので)

2023/05/06 11:46

投稿

crhg
crhg

スコア1177

test CHANGED
@@ -5,12 +5,12 @@
5
5
  ```php
6
6
  $query = Article::query();
7
7
  $query->whereDoesntHave('tags',function ($q){
8
- return $q->whereIn('tags.id', [1,3]);
8
+ return $q->whereIn('tag.id', [1,3]);
9
9
  });
10
10
  ```
11
11
 
12
12
  ```
13
- > App\Models\Article::whereDoesntHave('tags', fn($q) => $q->whereIn('tags.id', [1,3]))->get()
13
+ > App\Models\Article::whereDoesntHave('tags', fn($q) => $q->whereIn('tag.id', [1,3]))->get()
14
14
  = Illuminate\Database\Eloquent\Collection {#6213
15
15
  all: [
16
16
  App\Models\Article {#7166

1

fix typo

2023/05/06 11:43

投稿

crhg
crhg

スコア1177

test CHANGED
@@ -5,7 +5,7 @@
5
5
  ```php
6
6
  $query = Article::query();
7
7
  $query->whereDoesntHave('tags',function ($q){
8
- return $q->whereIn('tag.id', [1,3]);
8
+ return $q->whereIn('tags.id', [1,3]);
9
9
  });
10
10
  ```
11
11