How can I bind params in multiple foreach loops?
With ? SQL output is wrong
'%term%'SELECT * FROM `user` WHERE (LOWER(`name`) LIKE '\\' ESCAPE '%second_term%') OR (LOWER(`name`) LIKE '\\' ESCAPE )
$attributes = $this->attributes;
$searchTerms = explode(' ', $term);
foreach (Arr::wrap($attributes) as $attribute) {
$sql = new Expression("LOWER(`{$attribute->getAttribute()}`) LIKE ? ESCAPE ?");
foreach ($searchTerms as $searchTerm) {
$searchTerm = mb_strtolower($searchTerm, 'UTF8');
$searchTerm = str_replace("\\", $this->getBackslashByPdo(), $searchTerm);
$searchTerm = addcslashes($searchTerm, "%_");
$attribute->isPartial()
? $query->orWhere("$sql")
->addParams(["%{$searchTerm}%", '\\'])
: $query->orWhere([$attribute->getAttribute() => $searchTerm]);
}
}