I'm working on an international website with 3 languages (Eng - FR and AR) based on laravel localization. And I want to set the locale prefix in hreflang tag.
My site is structured like this:
http://example.com/{locale}
<ul>
<a href="{{ url('lang/en') }}" hreflang="LANGUAGE PREFIX">English</a>
<a href="{{ url('lang/fr') }}" hreflang="LANGUAGE PREFIX">French</a>
<a href="{{ url('lang/ar') }}" hreflang="LANGUAGE PREFIX">Arabic</a>
</ul>
routes/web.php
Route::get('lang/{locale}', [LocalizationController::class, 'lang']);
LocalizationController
class LocalizationController extends Controller
{
public function lang($locale) {
App::setlocale($locale);
session()->put('locale', $locale);
return redirect()->back();
}
}