@php
$currentLocale = app()->getLocale();
$targetLocale = $currentLocale === 'ar' ? 'en' : 'ar';
$segments = request()->segments();
if ($targetLocale === 'ar') {
// Switching to Arabic → add /ar
if (!isset($segments[0]) || $segments[0] !== 'ar') {
array_unshift($segments, 'ar');
}
} else {
// Switching to English → remove /ar
if (isset($segments[0]) && $segments[0] === 'ar') {
array_shift($segments);
}
}
$url = '/' . implode('/', $segments);
if ($url === '/') {
$url = $targetLocale === 'ar' ? '/ar' : '/';
}
@endphp
{{ $currentLocale === 'ar' ? __('header.switch_en') : __('header.switch_ar') }}