Greetings to everyone in the community
I have a problem when I want to try to place a multi-language site, I have downloaded the language packs and put them in the resources / lang folder of Laravel 5.2
I have configured my view like this:
<li><a href="{{url('lang',['es'])}}"><img src="digitales/RecursoSistema/imagenes/spain.png"> Español</a></li>
<li class="divider"></li>
<li><a href="{{url('lang',['en'])}}"><img src="digitales/RecursoSistema/imagenes/united-states.png"> English</a></li>
<li class="divider"></li>
<li><a href="{{url('lang',['zh'])}}"><img src="digitales/RecursoSistema/imagenes/china.png"> 中国</a></li>
I have configured my route like this:
Route::get('lang/{lang}',function ($lang){
session(['lang' => $lang]);
return \Redirect::back();
})->where([
'lang' => 'en|es|zh'
]);
I have created a Middleware which is called as LangMiddleware like this:
public function handle($request, Closure $next)
{
if(!empty(session('lang')))
{
\App::setLocale('lang');
}
return $next($request);
}
Register my Middleware as well in the Kernel.php file:
protected $middlewareGroups = [
'web' => [
\reconsafe\Http\Middleware\LangMiddleware::class,
\reconsafe\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\reconsafe\Http\Middleware\VerifyCsrfToken::class,
],
And I have placed the routes in a main Middleware group telling you to point to the group called 'web'asi:
Route::group(['middleware' => ['web']], function(){
Route::get('lang/{lang}',function ($lang){
session(['lang' => $lang]);
return \Redirect::back();
})->where([
'lang' => 'en|es|zh'
]);
Route::group(['prefix'=>'principal','namespace'=>'\Principal'],function(){
Route::resource('paises','PaisController');
Route::resource('provincias','ProvinciaController');
});
});
The problem is that when I click on the links in the view, the language does not change ... it keeps showing the default one in the config / app.php the funny thing is that if I click on the links it goes away by default in the fallback_locale ... and check the session variable and if you save the values I sent you.
To make sure that Laravel is taking the values of the language, if I manually put the value in the config / app.php if it works, the problem is if I click on the links ...
Honestly I do not know what I'm doing wrong ... something tells me it's Middleware but I'm not sure, I need guidance to see what is wrong.
I hope you can help me.