Home > other >  Add Variable to Livewire Navigation Menu
Add Variable to Livewire Navigation Menu

Time:10-19

I am trying to add a variable($countTeacherDuplicates) which contains a count of an array beside the navigation link title. I have already registered the variable as a global array in the AppServiceProviders. I just couldn't quite get how the syntax works

Tried this so far but totally getting syntax error

<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
                <x-jet-nav-link href="{{ route('join-teach') }}" :active="request()->routeIs('join-teach')">
                    {{ __('Instructor Conflicts','('$countTeacherDuplicates')') }}
                </x-jet-nav-link>
            </div>

Can anyone help me this is the last piece for my project.Thanks to whoever responds.

CodePudding user response:

<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
 <x-jet-nav-link href="{{ route('join-teach') }}" :active="request()->routeIs('join-teach')">
  {{ __("Instructor Conflicts {$countTeacherDuplicates}") }}
 </x-jet-nav-link>
</div>
Output: Instructor Conflicts 1

also

<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
 <x-jet-nav-link href="{{ route('join-teach') }}" :active="request()->routeIs('join-teach')">
  {{ __('Instructor Conflicts' . "('$countTeacherDuplicates')") }}
 </x-jet-nav-link>
</div>
Output: Instructor Conflicts('1')

Note: You used , "comma". For translation e.g {{text}}, /vendor/laravel/framework/src/Illuminate/Translation/Translator.php's get method is used to called. So pass correct parameters.

public function get($key, array $replace = [], $locale = null, $fallback = true)

NB: On the other hand . "dot" is a string concatenator.

  • Related