Laravel Add active class to Nav Menu System

Today, We want to share with you Laravel Add active class to Nav Menu System.In this post we will show you Dynamically Add Active Classes To Nav With PHP and Bootstrap, hear for Laravel dynamically add active classes to nav with php and bootstrap we will give you demo and example for implement.In this post, we will learn about Add active class to nav links based on URL with Laravel Address with an example.

Laravel Add active class to Nav Menu System

There are the Following The simple About Laravel Add active class to Nav Menu System Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Add Active Navigation Class Based on URL, so the Laravel Dynamic Menu System for this example is following below.

Also Read :  Remove Last Character from String jQuery

Setp 1: Laravel Blade File HTML


<h2>Laravel Add active class to Nav Menu System</h2>
<!-- Sidebar Menu -->
<aside class="main-sidebar">
    <section class="sidebar">
        <ul id="sidebarnav">
                <li {!! classSelectedPath('home') !!}><a href="{{ url('home') }}" {!! classActivePath('home') !!}><i class="fa fa-tachometer"></i><span>Dashboard</span></a></li>
                <li {!! classSelectedPath('members') !!}><a href="{{ url('members') }}" {!! classActivePath('members') !!}><i class="fa fa-ticket"></i><span>All Members</span> <span class="badge badge-pill badge-warning
">{{ $activemembers }}</span></a> </li>
                <li {!! classSelectedPath('complete') !!}><a href="{{ url('complete') }}" {!! classActivePath('complete') !!}><i class="fa fa-folder"></i><span>Completed Members</span> <span class="badge badge-pill badge-warning
">{{$completemembers}}</span></a> </li>
                    <li {!! classSelectedPath('Stores') !!}><a href="{{ url('Stores') }}" {!! classActivePath('Stores') !!}><i class="fa fa-shopping-bag"></i><span>Stores</span></a></li>
                    <li {!! classSelectedPath('Repots') !!}><a href="{{ url('Repots') }}"  classActivePath('Repots') !!}><i class="fa fa-list-ol"></i><span>Repots</span></a></li>
                    <li {!! classSelectedPath('Balance') !!}><a href="{{ url('Balance') }}" classActivePath('Balance') !!}><i class="fa fa-list-ul"></i><span>Balance</span></a></li>
                    <li {!! classSelectedPath('earnings') !!}><a href="{{ url('earnings') }}" {!! classActivePath('earnings') !!}><i class="fa fa-sliders"></i><span>Earnings</span></a></li>
                    <li {!! classSelectedPath('Menus') !!}><a href="{{ url('Menus') }}" {!! classActivePath('Menus') !!}><i class="fa fa-sitemap"></i><span>Menus</span></a></li>
                    <li {!! classSelectedPath('modes') !!}><a href="{{ url('modes') }}" {!! classActivePath('modes') !!}><i class="fa fa-tasks"></i><span>Modes</span></a></li>
                    <li {!! classSelectedPath('Auto-response') !!}><a href="{{ url('Auto-response') }}" {!! classActivePath('Auto-response') !!}><i class="fa fa-reply-all"></i><span>Auto response</span></a></li>
                    <li {!! classSelectedPath('ticket-email-card') !!}><a href="{{ url('ticket-email-card') }}" {!! classActivePath('ticket-email-card') !!}><i class="fa fa-envelope"></i><span>Email Card</span></a></li>
                    <li {!! classSelectedPath('permissions') !!}><a href="{{ url('permissions') }}" {!! classActivePath('permissions') !!}><i class="fa fa-users"></i><span>Permissions</span></a></li>
                    <li {!! classSelectedPath('settings') !!}><a href="{{ url('settings') }}" {!! classActivePath('settings') !!}><i class="fa fa-wrench"></i><span>Settings</span></a></li>
    <!--<div class="plan-icon">
        <a href="plan.html" class="plan-btn">
            <img src="images/plan.svg" alt="">
<!-- End Sidebar Menu -->
<a href="" target="_blank" alt="pakainfo" title="pakainfo">Free Download Example -</a>

Setp 2: Create Custom Laravel helpers


if (!function_exists('classActivePath')) {
    function classActivePath($path)
        $parts = explode('/', \Request::path());
        if ($parts[0] == $path || \Request::is($path)) {
            return 'class="active"';

        return '';
if (!function_exists('classSelectedPath')) {
    function classSelectedPath($path)
        $parts = explode('/', \Request::path());
        if ($parts[0] == $path || \Request::is($path)) {
            return 'class="selected"';

        return '';

Setp 3: project_name/composer.json

Add Register Path : “files”:[“app/library/helpers.php”]

Also Read :  Get Relative Cursor Coordinates Using jQuery

Include globally in composer.json

"autoload": {
    "classmap": [
    "psr-4": {
        "App\": "app/"
"autoload-dev": {
    "psr-4": {
        "Tests\": "tests/"
"extra": {
    "laravel": {
        "dont-discover": [

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Add active class to Nav Menu System.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

Laravel Advance Database Query Builder
Today, We want to share with you Laravel Advance Database Query Builder.In this post we will show you Database: Query

Add a Comment

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