i have an issue. If i give to my links routes, all of them becomes active
<li class="{{ (strpos(Route::currentRouteName(), 'dashboard') == 0) ? 'active' : '' }}">
<a href="{{ route('dashboard') }}">
<i class="uil uil-dashboard me-2 d-inline-block"></i>Dashboard</a></li>
Can somebody explain me why is that happening?
2
Answers
strpos
returnsint(0)
whenRoute::currentRouteName()
is'dashboard'
andbool(false)
otherwise.You’re using the
==
operator which is NOT strict comparison. Try using===
instead.You should use the
request()->route()->named()
method :https://laravel.com/docs/10.x/routing#inspecting-the-current-route