Article image

MAKE NAVBAR NAVIGATION LINKS ACTIVE IN LARAVEL

Laravel -

Sep 28 2019

Dino Numic

It looks much better if the current page that we are on is highlighted in the navbar. It tells the user which page he is on and it ads to the visuals of the application. In Laravel, it is relatively easy to achieve highlighted nav links.

In order to achieve this we will make an if check in the element class and conditionally add an active class if the condition is true. The condition will be whether current route matches the one we want to highlight like so.

@if(Request::is('a-route-name')) active @endif"

In a real example we would probably have a list with navigation links inside.

<li class="nav-item">
    <a class="nav-link @if(Request::is('about')) active @endif" href="{{ route('frontend.about') }}">About</a>
</li>

That is it. A simple solution to highlight an active navigation link.