Laravel lang slug in url

Asked by At

I've followed this article to add multi language into my app and it's working fine, the only issue i need to solve is that languages slug won't add to the url.


based on the article above i get my page in English like:

and in another language the same (however translation will placed)

what i want is like:



Any idea?

4 Answers

mafortis On Best Solutions


I used this tutorial and it gets me what I needed

sykez On

Perhaps you can try my answer here, where I used mcamara's Laravel Localization package to achieve this. It was painless for me :)

Jamsheer Mohammed On

Change your route using prefix

Route::prefix('{locale}')->group(function ($locale) {

    if (array_key_exists($locale, Config::get('languages'))) {
        Session::put('applocale', $locale);
    // else return 404 
    Route::get('your-slug', function () {    
Prafulla Kumar Sahu On

May be you can use App::getLocale() as route group prefix and use that to choose language .

In routing

Route::middleware(App::getLocale())->group(function () {
    Route::get('/', function () {
        // Uses first & second Middleware

    Route::get('user/profile', function () {
        // Uses first & second Middleware

Retrieve the request parameters in middleware and if require In your middleware you can put something like a conditional and reconstruct the url if required and then redirect it to the newly constructed url.

$locale = $request->segment(1);

if (in_array($locale, config('app.locales'))) {
            return $next($request);
} else {