Active Current Menu Item – Laravel

How to Use Request Segment ?

There are different ways to active the current menu. We will discuss 2 of them. They are given below

Trick 1

<li class="{{(request()->segment(2) == 'setting' )?'active open':''}}">

In above code, the requested URL of segment 2 is checked and matched with ‘setting’ , if satisfied the condition then respective class will applied

Trick 2

<li {{{ (Request::is('admin/dashboard','admin/dashboard/*') ? 'class = active' : '') }}}>

Here * is for everything. Trick 1 is for everything that comes after that segment whereas Trick 1 is applied according to the described structure.

Leave a Reply

Your email address will not be published. Required fields are marked *