I have multi-language website. In order to locale website I use middleware which look like this:
public function handle($request, Closure $next)
{
App::setlocale('pl');
Cookie::queue(Cookie::make('lang', 'pl'), true, 1440);
return $next($request);
}
My names of roote looks like this: 'pl.articles' or 'en.acritcles' so I use cookie to generate links into view. For example:
@if(Cookie::get('lang') == 'pl')
<li><a href="{{ route('pl.allwomens') }}">@lang('category.womens')</a></li>
@else
<li><a href="{{ route('en.allwomens') }}">@lang('category.womens')</a></li>
@endif
It works but I have a little problem. Actully when I change a language, links will bo to a previous version. So I must reload website in order to change links to. Sometimes I click some link and langage of my website will chang. I click again and language will come back to previous version. Where is the problem? I use middleware in a group
Route::group(['prefix' => 'pl', 'middleware' => ['PLLanguage', 'globalStats']], function(){