Level 28
What are you trying to achieve exactly? Can't you simply hardcode it like you hardcoded your 3 links?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm working on an international website with 3 languages (Eng - FR and AR) based on laravel localization. And I want to set the language prefix in hreflang tag.
My site is structured like this:
http://example.com/{locale}
<ul>
<a rel="alternate" hreflang="LANGUAGE PREFIX HERE..." href="{{ url('lang/en') }}">English</a>
<a rel="alternate" hreflang="LANGUAGE PREFIX HERE..." href="{{ url('lang/fr') }}">French</a>
<a rel="alternate" hreflang="LANGUAGE PREFIX HERE..." href="{{ url('lang/ar') }}">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();
}
}
Please or to participate in this conversation.