【发布时间】:2019-06-24 05:12:25
【问题描述】:
我在 Laravel v5.6 中写博客 翻译新路线时它对我不起作用 但是像登录和注册和登陆页面这样的旧路线在我进入新路线时也能正常工作,但不是
切换语言页面
Route::get('locale/{locale}', function ($locale) {
Session::put('locale', $locale);
return redirect()->back();
// this link will add session of language when they click to change langauge
})->name('locale');
Route::get('/{username}', 'ProfileAccountController@index')->name('profile')->middleware('admin.user');
当我走这条路时它不起作用,导航栏和页脚又回到关键点,删除此页面中的所有代码并测试它也不起作用的语言。
我使用了所有这些命令,什么也没用
php artisan config:cache
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
谢谢。
【问题讨论】:
-
您应该在应用程序的早期分配语言环境,可能在中间件或服务提供者中。 if(session()->get('locale')) app()->setLocale(session()->get('locale'))
-
当我删除中间件时它也能正常工作
标签: php laravel laravel-5.6