Laravel URL Generation: Default Values

Route::get('/{locale}/posts', function () {
    //
})->name('post.index');
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\URL;

class SetDefaultLocaleForUrls
{
    public function handle($request, Closure $next)
    {
        URL::defaults(['locale' => $request->user()->locale]);

        return $next($request);
    }
}

You may use the URL::defaults method to define a default value for this parameter that will always be applied during the current request.

Related concepts

Laravel URL Generation: Default Values — Structure map

Clickable & Draggable!

Laravel URL Generation: Default Values — Related pages: