Put Locale on Session - Laravel Multi-Language Tutorial ep-05

Put Locale on Session - Laravel Multi-Language Tutorial ep-05

Code With Tony

8 месяцев назад

1,459 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Code With Tony
Code With Tony - 17.10.2023 14:34

Put Locale on Session - Laravel Multi-Language Tutorial

Ответить
Hagar Osama
Hagar Osama - 18.10.2023 01:38

I did try to do localization without a controller and I did the dropdown. Still, I have two problems one is that I want to achieve a default locale as in Apple site in the previous video. I don't know how and the second if I am on a product page with an id as a parameter it gives me an error that I need to pass the id parameter, how do I fix this error without passing the id because it is cumbersome to pass every id in the route. this is my code in the dropdown @foreach(config('app.languages') as $language)
<li><a href="{{route(Route::currentRouteName(), ['locale' => $language['locale']])}}">{{$language['name']}}</a></li>
@endforeach
and this is the middleware
public function handle(Request $request, Closure $next): Response
{
$lang = $request->segment(1)
foreach (config('app.languages') as $language) {
if ($lang == $language['locale']) {
App::setLocale($lang);
}
}
URL::defaults(['locale' => $lang]);
return $next($request);
}

I tried to fix these two problems many times but I failed to do so. so any help will be appreciated

Ответить