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.

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><a href="{{ url('home') }}"><i class="fa fa-tachometer"></i><span>Dashboard</span></a></li>
                <li><a href="{{ url('members') }}"><i class="fa fa-ticket"></i><span>All Members</span> <span class="badge badge-pill badge-warning
">{{ $activemembers }}</span></a> </li>
                <li><a href="{{ url('complete') }}"><i class="fa fa-folder"></i><span>Completed Members</span> <span class="badge badge-pill badge-warning
">{{$completemembers}}</span></a> </li>
                    <li><a href="{{ url('Stores') }}"><i class="fa fa-shopping-bag"></i><span>Stores</span></a></li>
                    <li><a href="{{ url('Repots') }}"><i class="fa fa-list-ol"></i><span>Repots</span></a></li>
                    <li><a href="{{ url('Balance') }}"><i class="fa fa-list-ul"></i><span>Balance</span></a></li>
                    <li><a href="{{ url('earnings') }}"><i class="fa fa-sliders"></i><span>Earnings</span></a></li>
                    <li><a href="{{ url('Menus') }}"><i class="fa fa-sitemap"></i><span>Menus</span></a></li>
                    <li><a href="{{ url('modes') }}"><i class="fa fa-tasks"></i><span>Modes</span></a></li>
                    <li><a href="{{ url('Auto-response') }}"><i class="fa fa-reply-all"></i><span>Auto response</span></a></li>
                    <li><a href="{{ url('ticket-email-card') }}"><i class="fa fa-envelope"></i><span>Email Card</span></a></li>
                    <li><a href="{{ url('permissions') }}"><i class="fa fa-users"></i><span>Permissions</span></a></li>
                    <li><a href="{{ url('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" 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”]

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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Sudo Unable To Resolve Host Error in Linux - Fix sudo
  2.   Loading JSON data to Highcharts data from JSON Response
  3.   How validate/verification OTP in PHP?
  4.   Laravel Dynamic Active Class Menu
  5.   PHP Multiple images upload using jQuery Ajax
  6.   Bootstrap change tooltip content on click jQuery
  7.   Top 10 Common PHP Job Interview Questions and Answers
  8.   PHP Laravel Set Active Menu Examples
  9.   PHP Laravel 5 Class Form HTML not found Resolve Error
  10.   php calculate date difference in laravel carbon query