Надеюсь, что этот код будет работать для вас.
Контроллер
public function index($locale)
{
session(['locale' => $locale]);
App::setLocale($locale);
return Redirect::back();
}
Язык Middleware:
public function handle($request, Closure $next)
{
if (Session::has('locale')) {
App::setLocale(Session::get('locale'));
}
else { // This is optional as Laravel will automatically set the fallback language if there is none specified
App::setLocale(Config::get('app.fallback_locale'));
}
return $next($request);
}
Маршрут:
Route::get('/{lang}', 'LanguageController@index');
Последнее добавление промежуточного программного обеспечения Langauge в приложении /Http/Kernal.php в middlewaregroup
\App\Http\Middleware\Language::class,
после многих исследований я пытаюсь, как это работает, но я хочу знать, работает индекс или нет
public async Task<ActionResult> Index1(Recherche m)
{
//var rentals = userIndex(m);
var userIndex = Builders<Utilisateur>.IndexKeys;
var indexModel = new CreateIndexModel<Utilisateur>(userIndex.Ascending(x => x.login));
await context.utilisateurs.Indexes.CreateOneAsync(indexModel).ConfigureAwait(false);
var filter = new BsonDocument("login", "admin");
var rentals = await context.utilisateurs.Find(filter).ToListAsync();
var model = new userList
{
Utilisateurs = rentals,
Motcle = m
};
return View(model);
}