我正在使用多语言网站。我已经为locale创建了一个中间件。 Locale与Home,Login&注册视图。但是,它无法与auth/passwords/reset.blade.php
和auth/passwords/email.blade.php
一起使用。当我按下注销时,Locale会话会破坏。
Laravel 5.3 routes / web.php
Route::group(['middleware' => 'locale'], function(){
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index');
});
Route::get('setlocale/{locale}', function($locale){
\Session::put('locale', $locale);
return back();
});
中间件:语言环境
<?php
namespace Onebook\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Config;
class Locale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$locale = 'en';
if(Session::has('locale')){
$locale = Session::get('locale');
}
else{
$locale = Config::get('app.locale');
}
\App::setlocale($locale);
return $next($request);
}
}