<?php
Route::get('/{locale}/post', function() {
return 'My post';
})->name('post');
Route::get('/try', function() {
return route('post');
})->middleware('locale');
'locale' => \App\Http\Middleware\SetDefaultLocaleForUrls::class,
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\URL;
class SetDefaultLocaleForUrls {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
URL::defaults(['locale' => config('app.locale')]);
return $next($request);
}
}