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

回答編集履歴

1

誤字

2020/09/14 22:13

投稿

tenlife
tenlife

スコア70

answer CHANGED
@@ -1,15 +1,14 @@
1
1
  コントローラーの記載を以下のように変更すると求めていた処理を実行できました。
2
2
  ```controller
3
- $private_items = Item::withoutGlobalScopes()->get();
4
- $private_items = $private_items->where('status', '1');
3
+ $private_items = $user->items()->withoutGlobalScopes()->where('status', '1')->get();
5
4
  ```
6
5
 
7
6
  気になる点
8
7
  以下のように引数を入れると"withoutGlobalScopes() must be of the type array or null, string given"のエラーが表示されます。"arrayかnullであるべきなのに、文字列が渡っている" と理解しています。
9
8
  ```ここに言語を入力
10
- $private_items = Item::withoutGlobalScopes()->get();
9
+ $private_items = $user->items()->withoutGlobalScopes()->where('status', '1')->get();
11
10
  ⬇️
12
- $private_items = Item::withoutGlobalScopes(ScopeItem::class)->get();
11
+ $private_items = $user->items()->withoutGlobalScopes(ScopeItem::class)->where('status', '1')->get();
13
12
  ```
14
13
 
15
14
  なぜstring判定されてしまうのでしょうか?