Redesign
This commit is contained in:
@@ -10,8 +10,12 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class IkeaProductsController extends Controller
|
||||
{
|
||||
public function search(Request $request, string $item, string $country = '')
|
||||
public function search(Request $request, string $field, string $text, ?string $country = '')
|
||||
{
|
||||
return IkeaProducts::search($item, $country);
|
||||
return IkeaProducts::search($field, $text, $country);
|
||||
}
|
||||
public function multi_search(Request $request, string $item, ?string $desc='', ?string $code='', ?string $country = '')
|
||||
{
|
||||
return IkeaProducts::search($item,$desc,$code,$country);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ class ProductsCompareController extends Controller
|
||||
|
||||
$cHash = CountryCode::code_countryHash();
|
||||
if (is_array($codes) == false)
|
||||
$aCodes = [$codes['code']];
|
||||
$aCodes = $codes;
|
||||
else
|
||||
$aCodes = $codes->map(function ($code) {
|
||||
return $code['code'];
|
||||
return $code;
|
||||
});
|
||||
|
||||
$products = IkeaProducts::whereIn("code", $aCodes);
|
||||
@@ -57,9 +57,9 @@ class ProductsCompareController extends Controller
|
||||
return $product;
|
||||
});
|
||||
Log::info("{products}", ["products" => $products]);
|
||||
return Inertia::render('IkeaRoot', [
|
||||
return [
|
||||
'products' => $products,
|
||||
'countryHash' => $cHash,
|
||||
]);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,21 @@ class IkeaProducts extends Model
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected function search($item,$country = '')
|
||||
protected function search($field, $text, $country)
|
||||
{
|
||||
if (strlen($item) >= 2 && strlen($item) < 5) {
|
||||
$result = $this->where('name', 'LIKE', $item . '%');
|
||||
if ($country != '') $result = $result->where('country',$country);
|
||||
if ((strlen($text) >= 2 && $field == "name") || (strlen($text) > 3 && $field == 'typeName')) {
|
||||
$result = $this->where($field, 'LIKE', '%' . $text . '%');
|
||||
if ($country != '') {
|
||||
$result->where('country', $country);
|
||||
}
|
||||
return $result->get();
|
||||
} else if (strlen($item >= 5)) {
|
||||
$result = $this->where(function ($query) use ($item) { $query->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%'); } );
|
||||
if ($country != '') $result = $result->where('country',$country);
|
||||
|
||||
return $result->get();
|
||||
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function multisearch($codes, $countries) {
|
||||
protected function multisearch($codes, $countries)
|
||||
{
|
||||
//$countries = $
|
||||
// return $this->where('code',$codes)->where('country',$countries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user