From e55e88fa6242cc23ddeb1ddac57def5bcaaae104 Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Tue, 26 Dec 2023 16:03:10 +0100 Subject: [PATCH] fix name of country --- app/Http/Controllers/ProductsCompareController.php | 4 +++- app/Models/CountryCode.php | 11 ++++++++++- resources/js/Pages/IkeaRoot.vue | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProductsCompareController.php b/app/Http/Controllers/ProductsCompareController.php index b515377..f1a7e8e 100644 --- a/app/Http/Controllers/ProductsCompareController.php +++ b/app/Http/Controllers/ProductsCompareController.php @@ -32,6 +32,7 @@ class ProductsCompareController extends Controller $countries = []; } + $cHash = CountryCode::code_countryHash(); if (is_array($codes) == false) $aCodes = [$codes['code']]; else @@ -51,7 +52,8 @@ class ProductsCompareController extends Controller }); Log::info("{products}", ["products" => $products]); return Inertia::render('IkeaRoot', [ - 'products' => $products + 'products' => $products, + 'countryHash' => $cHash, ]); } } diff --git a/app/Models/CountryCode.php b/app/Models/CountryCode.php index 86c4ab8..080fa96 100644 --- a/app/Models/CountryCode.php +++ b/app/Models/CountryCode.php @@ -39,6 +39,15 @@ class CountryCode extends Model $codes = $this->select('country_name', 'country_code')->get(); return $codes->mapWithKeys(function ($item) { return [$item['country_name'] => $item['country_code']]; -}); + }); } + + protected function code_countryHash() + { + $codes = $this->select('country_name', 'country_code')->get(); + return $codes->mapWithKeys(function ($item) { + return [$item['country_code'] => $item['country_name']]; + }); + } + } diff --git a/resources/js/Pages/IkeaRoot.vue b/resources/js/Pages/IkeaRoot.vue index 9fd67e5..09639a8 100644 --- a/resources/js/Pages/IkeaRoot.vue +++ b/resources/js/Pages/IkeaRoot.vue @@ -23,12 +23,17 @@ const props = defineProps({ type: Object, default: [] }, + countryHash: { + type: Object, + default: [] + }, }) - + console.log(props.countryHash); let tproducts = computed(() => { return props.products.map((prod) => { prod.salesPrice = parseFloat(prod.salesPrice); + prod.country = props.countryHash[prod.country]; return prod; } ) })