Answer the question
In order to leave comments, you need to log in
How is it customary in Laravel to set the active option for a menu item (bootstrap 4)?
Hello.
Standard situation: you need to display the menu item as active depending on the current uri.
Without using javascript.
How does Laravel deal with this issue?
Where exactly to render menu depending on uri?
It so happens to me there that for one menu - in fact, several controllers (the pages have different functionality)
That is, rendering in controllers is not an option. I also don’t really want to shove a lot of code into the view ...
What do you advise?
Thank you.
Answer the question
In order to leave comments, you need to log in
So far I've found this to show:
<li class="{{ Request::is('products*') ? 'active' : '' }}">
<a href="{!! route('products.index') !!}"><span>Products</span></a>
</li>
<li class="{{ Request::is('tags*') ? 'active' : '' }}">
<a href="{!! route('tags.index') !!}"><span>Tags</span></a>
</li>
<li class="{{ Request::is('items*') ? 'active' : '' }}">
<a href="{!! route('items.index') !!}"><span>Items</span></a>
</li>
Check the active route.
Even if the URL of the page changes, by the name of the route it will be available and nothing will break.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question