phplaravellaravel-translatable

Laravel spatie/laravel-translatable


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?


Solution

  • 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