From e07245e69acd372ba4816424f8c286a8fc640999 Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode Date: Sun, 23 Nov 2025 23:13:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=8D=20Refactor=20domain=20image=20logi?= =?UTF-8?q?c=20into=20reusable=20helper=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Moved domain image selection logic into `get_domain_image` helper for reusability. - Simplified `app-logo-icon.blade.php` and `SeoDataAttribute` by replacing inline logic with the new helper. - Improved maintainability and consistency for handling `lang_country` sessions. --- app/Attributes/SeoDataAttribute.php | 23 +------------ app/helpers.php | 34 +++++++++++++++++++ .../views/components/app-logo-icon.blade.php | 29 ++-------------- 3 files changed, 37 insertions(+), 49 deletions(-) diff --git a/app/Attributes/SeoDataAttribute.php b/app/Attributes/SeoDataAttribute.php index cd83d30..051bc15 100644 --- a/app/Attributes/SeoDataAttribute.php +++ b/app/Attributes/SeoDataAttribute.php @@ -17,28 +17,7 @@ class SeoDataAttribute private static function initDefinitions(): void { - $langCountry = session('lang_country', 'de-DE'); - $domainImage = asset('img/domains/'.$langCountry.'.jpg'); - if (!file_exists(public_path('img/domains/'.$langCountry.'.jpg'))) { - $langCountry = 'de-DE'; - } - $southAmericanCountries = [ - 'ar-AR', // Argentina - 'bo-BO', // Bolivia - 'br-BR', // Brazil - 'cl-CL', // Chile - 'co-CO', // Colombia - 'ec-EC', // Ecuador - 'gy-GY', // Guyana - 'py-PY', // Paraguay - 'pe-PE', // Peru - 'sr-SR', // Suriname - 'uy-UY', // Uruguay - 've-VE', // Venezuela - ]; - if (in_array($langCountry, $southAmericanCountries, true)) { - $domainImage = asset('img/domains/lat.png'); - } + $domainImage = get_domain_image(); self::$seoDefinitions = [ 'login' => new SEOData( diff --git a/app/helpers.php b/app/helpers.php index 61d412e..8b38672 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -13,3 +13,37 @@ if (!function_exists('route_with_country')) { return route($name, $parameters, $absolute); } } + +if (!function_exists('get_domain_image')) { + function get_domain_image(): string + { + $langCountry = session('lang_country', 'de-DE'); + + // Check if specific domain image exists + if (!file_exists(public_path('img/domains/'.$langCountry.'.jpg'))) { + $langCountry = 'de-DE'; + } + + $southAmericanCountries = [ + 'ar-AR', // Argentina + 'bo-BO', // Bolivia + 'br-BR', // Brazil + 'cl-CL', // Chile + 'co-CO', // Colombia + 'ec-EC', // Ecuador + 'gy-GY', // Guyana + 'py-PY', // Paraguay + 'pe-PE', // Peru + 'sr-SR', // Suriname + 'uy-UY', // Uruguay + 've-VE', // Venezuela + ]; + + // Use LAT image for South American countries + if (in_array($langCountry, $southAmericanCountries, true)) { + return asset('img/domains/lat.png'); + } + + return asset('img/domains/'.$langCountry.'.jpg'); + } +} diff --git a/resources/views/components/app-logo-icon.blade.php b/resources/views/components/app-logo-icon.blade.php index 47ffe96..97c642a 100644 --- a/resources/views/components/app-logo-icon.blade.php +++ b/resources/views/components/app-logo-icon.blade.php @@ -1,29 +1,4 @@ -@php - $langCountry = session('lang_country', 'de-DE'); - $domainImage = asset('img/domains/'.$langCountry.'.jpg'); - if (!file_exists(public_path('img/domains/'.$langCountry.'.jpg'))) { - $langCountry = 'de-DE'; - } - $southAmericanCountries = [ - 'ar-AR', // Argentina - 'bo-BO', // Bolivia - 'br-BR', // Brazil - 'cl-CL', // Chile - 'co-CO', // Colombia - 'ec-EC', // Ecuador - 'gy-GY', // Guyana - 'py-PY', // Paraguay - 'pe-PE', // Peru - 'sr-SR', // Suriname - 'uy-UY', // Uruguay - 've-VE', // Venezuela - ]; - if (in_array($langCountry, $southAmericanCountries, true)) { - $domainImage = asset('img/domains/lat.png'); - } -@endphp - -@if($langCountry === 'de-DE') +@if(session('lang_country', 'de-DE') === 'de-DE') @@ -41,5 +16,5 @@ @else - {{ $langCountry }} + {{ session('lang_country', 'de-DE') }} @endif