Я получаю все идентификаторы владельцев, но когда я применяю его к запросу, запрос не дает результата
Я пытаюсь увидеть его sql-код, применяю код к mysql и получаю результат, но вижу, что не получил результат
Код: Выделить всё
if ($request->filled('lead_owner') && $request->filled('lead_owner_text')) {
$filterType = $request->input('lead_owner');
$ownerText = $request->input('lead_owner_text');
if (is_array($filterType)) {
$ownerIds = [];
foreach ($filterType as $type) {
if ($type === 'startWith' && !empty($ownerText)) {
$ownerIds = array_merge($ownerIds, CompanyUsers::where('companyId', $user->companyId)
->whereRaw("LEFT(name, ?) = ?", [strlen($ownerText), $ownerText])
->pluck('id')->toArray());
} elseif ($type === 'endWith' && !empty($ownerText)) {
$ownerIds = array_merge($ownerIds, CompanyUsers::where('companyId', $user->companyId)
->whereRaw("RIGHT(name, ?) = ?", [strlen($ownerText), $ownerText])
->pluck('id')->toArray());
} elseif ($type === 'contain' && !empty($ownerText)) {
$ownerIds = array_merge($ownerIds, CompanyUsers::where('companyId', $user->companyId)
->where('name', 'like', "%{$ownerText}%")
->pluck('id')->toArray());
} elseif ($type === 'doesntContain' && !empty($ownerText)) {
$ownerIds = array_merge($ownerIds, CompanyUsers::where('companyId', $user->companyId)
->where('name', 'not like', "%{$ownerText}%")
->pluck('id')->toArray());
}
}
if (!empty($ownerIds)) {
$query->whereIn('lead_owner_id', $ownerIds);
}
}
}
Код: Выделить всё
$query->whereIn('lead_owner_id', $ownerIds);
Подробнее здесь: https://stackoverflow.com/questions/792 ... query-body
Мобильная версия