@if (!empty($metatags))
{{-- Basic Meta Tags --}}
@if (!empty($metatags['keywords']))
@endif
{{ $metatags['title'] ?? config('settings.site_name') }}
@if (!empty($metatags['time']))
@endif
{{-- Security Headers --}}
{{-- Canonical --}}
@if (!empty($metatags['canonical']))
@else
{{-- Generate clean canonical URL without language prefix conflicts --}}
@php
$currentUrl = url()->current();
$canonicalUrl = $currentUrl;
// Remove language prefix if it exists and we're on a localized route
if (app()->getLocale() !== config('app.fallback_locale')) {
$localePrefix = '/' . app()->getLocale();
if (str_starts_with($currentUrl, $localePrefix)) {
$canonicalUrl = str_replace($localePrefix, '', $currentUrl);
}
}
// Ensure we have a clean base URL
$canonicalUrl = rtrim($canonicalUrl, '/');
if (empty($canonicalUrl)) {
$canonicalUrl = url('/');
}
@endphp
@endif
{{-- Favicon --}}
{{-- PWA Manifest --}}
{{-- PWA Meta Tags --}}
{{-- Apple Touch Icons --}}
{{-- Microsoft Tiles --}}
{{-- Open Graph --}}
@php
// Use the same canonical URL logic for Open Graph
$currentUrl = url()->current();
$ogUrl = $currentUrl;
// Remove language prefix if it exists
if (app()->getLocale() !== config('app.fallback_locale')) {
$localePrefix = '/' . app()->getLocale();
if (str_starts_with($currentUrl, $localePrefix)) {
$ogUrl = str_replace($localePrefix, '', $currentUrl);
}
}
$ogUrl = rtrim($ogUrl, '/');
if (empty($ogUrl)) {
$ogUrl = url('/');
}
@endphp
{{-- Twitter --}}
@if (!empty($metatags['twitter_site']))
@endif
@if (!empty($metatags['twitter_creator']))
@endif
{{-- Performance --}}
{{-- Hreflang Tags --}}
@php
$locales = ['ar', 'en'];
$currentPath = request()->path();
$pathWithoutLocale = preg_replace('/^(ar|en)\/?/', '', $currentPath);
// Check if this is a blog page
if (preg_match('/^blogs\/(.+)$/', $pathWithoutLocale, $matches)) {
$currentSlug = urldecode($matches[1]);
// Try multiple methods to find the blog
$blog = \App\Models\Blog::whereRaw("JSON_EXTRACT(slug, '$.ar') = ?", [$currentSlug])
->orWhereRaw("JSON_EXTRACT(slug, '$.en') = ?", [$currentSlug])
->first();
// If not found with JSON_EXTRACT, try manual search
if (!$blog) {
$blogs = \App\Models\Blog::all();
foreach ($blogs as $b) {
foreach (['ar', 'en'] as $lang) {
$blogSlug = $b->getTranslation('slug', $lang);
if ($blogSlug === $currentSlug) {
$blog = $b;
break 2;
}
}
}
}
if ($blog) {
foreach ($locales as $locale) {
$localizedUrl = $blog->getLocalizedUrl($locale);
if ($localizedUrl) {
echo '';
}
}
// Add x-default pointing to Arabic (default language)
$defaultUrl = $blog->getLocalizedUrl('ar');
if ($defaultUrl) {
echo '';
}
} else {
// Fallback to simple method if blog not found
$path = $pathWithoutLocale ? '/' . $pathWithoutLocale : '';
foreach ($locales as $locale) {
echo '';
}
// Add x-default pointing to Arabic
echo '';
}
} else {
// For non-blog pages, use the simple method
$path = $pathWithoutLocale ? '/' . $pathWithoutLocale : '';
foreach ($locales as $locale) {
echo '';
}
// Add x-default pointing to Arabic
echo '';
}
@endphp
{{-- Google Tag Manager --}}
@if (config('settings.google_tag_manager_id'))
@endif
{{-- Google Analytics --}}
@if (config('settings.google_analytics_id'))
@endif
@endif
{{-- Schema JSON-LD --}}
@if (!empty($schema))
@else
{{-- Default WebPage Schema (safe encoding) --}}
@php
// Use the same canonical URL logic for schema
$currentUrl = url()->current();
$schemaUrl = $currentUrl;
// Remove language prefix if it exists
if (app()->getLocale() !== config('app.fallback_locale')) {
$localePrefix = '/' . app()->getLocale();
if (str_starts_with($currentUrl, $localePrefix)) {
$schemaUrl = str_replace($localePrefix, '', $currentUrl);
}
}
$schemaUrl = rtrim($schemaUrl, '/');
if (empty($schemaUrl)) {
$schemaUrl = url('/');
}
@endphp
@endif
{{-- FAQ Schema --}}
@if (!empty($faq_schema))
@endif
{{-- Breadcrumb Schema --}}
@if (!empty($breadcrumb_schema))
@endif
{{-- Google Tag Manager --}}
@if (config('settings.google_tag_manager_id'))
@endif
{{-- Google Analytics --}}
@if (config('settings.google_analytics_id'))
@endif
{{-- Default Schema for Organization and Website --}}
@if (empty($schema))
@endif
{{-- Lazy Loading Images --}}
{{-- Web Vitals --}}