laravellaravel-bladelaravel-localization

Laravel Localization add class active if open this Local


I'm trying to do what language is included in it added class"active"

I try this way but it doesn't work for me

    <div class="lang">
       <ul>
           @foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
              <li>
                  <a 
                      class="{{ Request::path() === LaravelLocalization::getLocalizedURL() ? 'active' : ''}}"
                      rel="alternate"
                      hreflang="{{ $localeCode }}"
                      href="{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}">
                      {{ $properties['native'] }}
                  </a>                                    
              </li>
           @endforeach
       </ul>
     </div>

Solution

  • You should do:

    {{ $localeCode == LaravelLocalization::getCurrentLocale() ? 'active' : ''}}