How to set Locale Laravel right?

Middleware
class Localization
{
/**
 * Handle an incoming request.
*
 * @param \Illuminate\Http\Request $request
 * @param \Closure $next
 * @return mixed
*/
 public function handle($request, Closure $next)
{
 if (Session::has('locale')){
App::setLocale(Session::get('locale'));
}
 return $next($request);
}
}


Select
<form action="{{route('language-switcher')}}" method="post" id="lang-switcher">
 <div class="search-container">
 <select name="change" id="font-options">
 <option {{(App::isLocale('EN')) ? 'selected' : "}} value="ru">RU</option>
 <option {{(App::isLocale('en')) ? 'selected' : "}} value="en">EN</option>
</select>
{{csrf_field()}}
 <div class="search-arrow"></div>
</div>
</form>


// Controller
public function switcher(Request $request){

 $locale = $request->change;

 Session::put('locale', $locale);
 return redirect()->back();
 }


Route
// Home
Route::get('/', 'MainController@index')->name('index');

// About
Route::get('/about', 'MainController@about')->name('about');

// Lang Switcher
Route::post('/switcher-language/', 'MainController@switcher')->name('language-switcher');


Question:
At the moment, the location is determined via the session and load the desired content, as do to the main language (EN) was the link /about and in English. (en) /en/about
April 3rd 20 at 17:20
0 answer

Find more questions by tags Laravel