A
A
Alexfixer2020-10-15 14:58:25
Laravel
Alexfixer, 2020-10-15 14:58:25

How to add active to product categories?

How to write a condition for adding the Active class to the category of goods to which we are moving?
So I tried it, the active class is not added to li:
In view

<ul class="category">
    <li class="cat-item {{ Request::is('?cat={!!$category->id!!}') ? 'active' : '' }}">
         <a class="widget-cat widget-link" href="?cat={{$category->id}}">{{$category->title}}</a>
    </li>
 </ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrPofix, 2020-10-20
@MrPofix

Maybe so?

<ul class="category">
            <li class="cat-item {{ Request::query('cat') === $category->id ? 'active' : '' }}">
                <a class="widget-cat widget-link" href="?cat={{$category->id}}">{{$category->title}}</a>
            </li>
        </ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question