$teamIds = Team::where('options->stage', 'Subscribed')->pluck('id');
$documents = Document::where(function ($query) {
$query->where('stage', '!=', 10)->orWhere('error', '!=', '');
})->whereIn('team_id', $teamIds)->get();
Oct 20, 2020
7
Level 4
Query with where + where or + where in not working
I am having some trouble getting this to respond correctly:
$teams = Team::where('options->stage', 'Subscribed')->get()->pluck('id')->toArray();
$str = implode(", ", $teams);
$documents = Document::where('stage', '!=', 10)->orWhere('error', '!=', '')->whereIn('team_id', [$str])->get();
The query output is this:
select
*
from
`documents`
where
(
`stage` != 10
or `error` != ''
and `team_id` in ('2, 7, 9, 24, 29, 32, 47')
)
and `documents`.`deleted_at` is null
But its returning documents where team_id is not in the array.
Level 75
Please or to participate in this conversation.