R
R
Roman2019-03-07 17:08:17
Laravel
Roman, 2019-03-07 17:08:17

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

3 answer(s)
R
Roman, 2019-03-07
@procode

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>

Well, why not... but I just want to somehow put url masks together - write the names of the routes - is this possible?

E
Eugene, 2019-08-03
@djon_pulse

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.

V
vism, 2019-03-07
@vism

Yes, it's possible, but what's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question