Fix complex query

This commit is contained in:
2024-03-21 21:11:17 +01:00
parent 65720e5433
commit 5aa4055be3

View File

@@ -41,11 +41,15 @@ class IkeaProducts extends Model
if (strlen($text) < 2) return [];
$result = $this;
if (strlen($text) >= 2) $result = $result->where("name", 'LIKE', '%'. $text . '%');
if (strlen($text) > 3) $result->orWhere("typeName", 'LIKE', '%'. $text . '%');
$result = $this->where(function ($query) use ($text) {
if (strlen($text) >= 2) $query->where("name", 'LIKE', '%'. $text . '%');
if (strlen($text) > 3) $query->orWhere("typeName", 'LIKE', '%'. $text . '%');
});
if ($country != '') {
$result->where('country', $country);
}
}
return $result->get();
}