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.
Use is()
method. For example:
<li class="{{ request()->is('sites/*/edit') ? 'active' : '' }}"
I am currently using Laravel 5.6.* and my solution is:
<a href="#" class="nav-link {{ request()->is('users*') ? 'active' : '' }}">Users</a>
There is also the following if you have named your route :
<li class="{{ Request::routeIs('admin') ? 'active' : '' }}">...</li>
Inspired from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With