{{-- TEL company card for Google (hidden structured data). Phones, email, address, map link and social pages come from the admin panel (Contact Info and Social Media). Services come from Admin -> Services. Only the values in the "Fixed values" block below are written here. --}} @if (request()->routeIs('home', 'contact')) @php try { // Fixed values (no admin field for these) $telOrgFounded = '2013'; $telOrgDays = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday']; $telOrgOpens = '09:00'; $telOrgCloses = '18:00'; $telOrgLogo = asset('images/Triangle-BD-Header-Logo.png'); $telFirst = function ($value) { if (is_array($value)) { foreach ($value as $v) { if (is_string($v) && trim($v) !== '') return trim($v); } return null; } return (is_string($value) && trim($value) !== '') ? trim($value) : null; }; $telList = function ($value) { $value = is_array($value) ? $value : [$value]; return array_values(array_filter(array_map(fn ($v) => is_string($v) ? trim($v) : '', $value), fn ($v) => $v !== '')); }; $telInfo = \App\Models\ContactInfo::first(); $telPhones = $telInfo ? $telList($telInfo->phone) : []; $telEmail = $telInfo ? $telFirst($telInfo->email) : null; $telAddress = $telInfo ? $telFirst($telInfo->address) : null; $telMap = $telInfo ? $telFirst($telInfo->map_direction) : null; // Address: full text as street address; city and postcode picked out when present. $telPostal = null; if ($telAddress) { $telPostal = ['@type' => 'PostalAddress', 'streetAddress' => $telAddress, 'addressCountry' => 'BD']; foreach (['Dhaka', 'Gazipur', 'Narayanganj', 'Chattogram', 'Chittagong', 'Khulna', 'Rajshahi', 'Sylhet', 'Barishal', 'Rangpur', 'Mymensingh', 'Cumilla', 'Savar'] as $telCity) { if (stripos($telAddress, $telCity) !== false) { $telPostal['addressLocality'] = $telCity; break; } } if (preg_match('/\b(\d{4})\b(?!.*\b\d{4}\b)/', $telAddress, $telM)) { $telPostal['postalCode'] = $telM[1]; } } // Social pages: active entries that point to a real page (not just facebook.com/). $telSocial = []; foreach (\App\Models\SocialMedia::where('status', 'Active')->pluck('link') as $telLink) { $telLink = trim((string) $telLink); $telPath = trim((string) parse_url($telLink, PHP_URL_PATH), '/'); if (filter_var($telLink, FILTER_VALIDATE_URL) && $telPath !== '') $telSocial[] = $telLink; } $telSocial = array_values(array_unique($telSocial)); // Services offered: active services, in admin order. $telOffers = \App\Models\Service::where('status', 'Active')->orderBy('sorting_no')->get(['name', 'slug']) ->map(fn ($s) => [ '@type' => 'Offer', 'itemOffered' => ['@type' => 'Service', 'name' => $s->name, 'url' => route('service-details', $s->slug)], ])->values()->all(); $telOrg = array_filter([ '@context' => 'https://schema.org', '@type' => 'ProfessionalService', '@id' => rtrim(url('/'), '/') . '/#organization', 'name' => config('app.name'), 'alternateName' => 'TEL', 'url' => url('/'), 'logo' => $telOrgLogo, 'image' => $telOrgLogo, 'description' => 'MEP, fire safety, HVAC, solar and green building engineering consultancy in Bangladesh.', 'foundingDate' => $telOrgFounded, 'telephone' => $telPhones[0] ?? null, 'email' => $telEmail, 'address' => $telPostal, 'hasMap' => $telMap, 'areaServed' => ['@type' => 'Country', 'name' => 'Bangladesh'], 'openingHoursSpecification' => [[ '@type' => 'OpeningHoursSpecification', 'dayOfWeek' => $telOrgDays, 'opens' => $telOrgOpens, 'closes' => $telOrgCloses, ]], 'contactPoint' => array_map(fn ($p) => [ '@type' => 'ContactPoint', 'telephone' => $p, 'contactType' => 'customer service', 'areaServed' => 'BD', 'availableLanguage' => ['English', 'Bengali'], ], $telPhones) ?: null, 'sameAs' => $telSocial ?: null, 'hasOfferCatalog' => $telOffers ? [ '@type' => 'OfferCatalog', 'name' => 'Engineering services', 'itemListElement' => $telOffers, ] : null, ], fn ($v) => $v !== null && $v !== ''); $telOrgJson = json_encode($telOrg, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG); } catch (\Throwable $e) { $telOrgJson = null; // never break the page because of this card } @endphp @if (!empty($telOrgJson)) @endif @endif