Basic search

This commit is contained in:
2023-12-25 17:23:45 +01:00
parent 3cfa2e3513
commit 4375ac1fc8
7 changed files with 161 additions and 50 deletions

View File

@@ -22,6 +22,10 @@ class CountryCodeController extends Controller
return CountryCode::active("Y");
}
public function codes()
{
return CountryCode::countryHash();
}
/**
* Store a newly created resource in storage.
*

View File

@@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use PhpParser\Node\Expr\Cast\String_;
class IkeaProductsController extends Controller
{

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\IkeaProducts;
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use App\Models\CountryCode;
use Inertia\Inertia;
class ProductsCompareController extends Controller
{
public function compare(Request $request)
{
$codes = $request->input("codes");
$countries = $request->input("countries");
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries]);
$codes = collect($codes);
// $countries = collect(json_decode($countries, true));
if ($countries != null && count($countries)) {
$hCountry = CountryCode::countryHash();
$countries = $countries->map(function ($country) {
return $hCountry[$country];
});
}
// $aCodes = $codes->map(function ($code) {
// return $code['code'];
// });
$aCodes = $codes['code'];
$products = IkeaProducts::where("code", $aCodes)->get();
Log::info("{products}", ["products" => $products]);
return Inertia::render('IkeaRoot', [
'products' => $products
]);
}
}

View File

@@ -7,30 +7,38 @@ use Illuminate\Database\Eloquent\Model;
class CountryCode extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'c_ikea_country_code';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'c_ikea_country_code';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'currency_code';
/**
* Indicates if the model's ID is auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
use HasFactory;
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'currency_code';
/**
* Indicates if the model's ID is auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
protected function active(String $status)
{
return $this->where('status', $status)->get();
}
use HasFactory;
protected function active(String $status)
{
return $this->where('status', $status)->get();
}
protected function countryHash()
{
$codes = $this->select('country_name', 'country_code')->get();
return $codes->mapWithKeys(function ($item) {
return [$item['country_name'] => $item['country_code']];
});
}
}

View File

@@ -32,4 +32,9 @@ class IkeaProducts extends Model
return [];
}
}
protected function multisearch($codes, $countries) {
//$countries = $
// return $this->where('code',$codes)->where('country',$countries);
}
}