From 103daee7fb3a6d1cd71dfe1b374171caeeffd2d5 Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Thu, 21 Mar 2024 10:11:20 +0100 Subject: [PATCH] fix length win search --- app/Models/IkeaProducts.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Models/IkeaProducts.php b/app/Models/IkeaProducts.php index 222dcfb..6d1cec9 100644 --- a/app/Models/IkeaProducts.php +++ b/app/Models/IkeaProducts.php @@ -36,8 +36,12 @@ class IkeaProducts extends Model } else if ($field == "all") { if (preg_match("/0[0-9]+/", $text)) { $result = $this->where("code", '=',$text); - } else - $result = $this->where("name", 'LIKE', '%'. $text . '%')->orWhere("typeName", 'LIKE', '%'. $text . '%'); + } else { + $result = $this; + + if (strlen($text) >= 2) $result = $result->where("name", 'LIKE', '%'. $text . '%'); + if (strlen($text) > 3) $result->orWhere("typeName", 'LIKE', '%'. $text . '%'); + } return $result->get(); }