Laravel spatie/laravel-translatable

1.2k Views Asked by At

this my route

Route::group(
    [
        'prefix' => LaravelLocalization::setLocale(),
        'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath','auth']
    ], function(){
       

this is working but I want to switch locale in blade like this

  <a  href="{{\App::setLocale('en')}}" >en</a>
  <a  href="{{\App::setLocale('uz')}}" >uz</a>

but it is not working , can you give some advise ??? What I should do?

2

There are 2 best solutions below

0
On BEST ANSWER

You can implement it like this:

@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
  <li>
    @if(LaravelLocalization::getCurrentLocale() != $localeCode)
      <a rel="alternate" hreflang="{{ $localeCode }}" href="{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}">
        {{ $localeCode }}
      </a>
    @endif
  </li>
@endforeach
0
On

The route middlewares that you use is for mcamara/laravel-localization package not spatie/laravel-translatable.
Back to the pacakage documentation, you can create a language selector you can use this snippet:
https://github.com/mcamara/laravel-localization#creating-a-language-selector