Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to set active class in my list item, but it doesn't work.

My code in blade:

@foreach($data as $site)
  <ul class="sidebar-menu" id="second-menu">
  @if(isAdmin())<li class="{{-- active class  for url parameter --}}"><a href="{{ url('sites/'.$site->id.'/edit') }}" >{{ $site->name }}</a></li>
@endif
</ul>
@endforeach

So, if I write: li class="@if(getRouteName() == 'site@index'){{ 'active' }}@endif" , it works nice, but in my case the problem is that I want to get 'active' class in foreach sites/'.$site->id.'/edit

Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use is() method. For example:

<li class="{{ request()->is('sites/*/edit') ? 'active' : '' }}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...