วิธีที่ฉันใช้งาน multilang คือผ่านมิดเดิลแวร์และเส้นทาง
Middleware Localization.php มีลักษณะดังนี้:
public function handle(Request $request, Closure $next)
{
$locale = $request->segment(1);
if(empty($locale)) {
return redirect()->to('/' . app()->getLocale());
}
if(in_array($locale, ['en','it'])) {
App::setLocale($locale);
$request->except(0);
}
return $next($request);
}
และใน web.php ของฉันฉันมี:
Route::get('locale/{locale}', function ($locale){
\Session::put('locale', $locale);
$path = Route::getCurrentRoute()->getPath();
return redirect($path);
})->name('langroute');
ในเบลดฉันใช้มันแบบนี้:
<a class="dropdown-item" href="{{ url('/en') }}">
ฉันจะเปลี่ยนเส้นทางกลับไปยังหน้าเดิมได้อย่างไรหลังจากเปลี่ยนเป็นภาษาอื่นแล้ว
href
ฉันได้ลองด้วย{{route(Route::currentRouteName(), 'en') }}
แล้ว แต่มันทำให้ฉันมีข้อผิดพลาดกับพารามิเตอร์บนเส้นทางเพจที่ต้องใช้พารามิเตอร์ - person Marinario Agalliu   schedule 12.01.2021->withInput()
ซึ่งรวมถึงสตริงการสืบค้นก่อนหน้า บางทีมันอาจจะช่วยได้ - person Taha Paksu   schedule 12.01.2021