Laravel Add active class to Nav Menu System

Laravel Technology

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.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

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.   Stopping On First Validation Failure in Laravel Bail Rule
  2.   Create Bootable USB Drive Steps - Bootable Pen Drive
  3.   jQuery Show Popup Message Few Seconds and Auto close
  4.   PHP Laravel Collection Sort By Multiple Fields
  5.   PHP Laravel Set Active Menu Examples
  6.   Insert update delete Using Laravel 5.2 Ajax CRUD laravel without refresh page
  7.   Laravel 6 Insert Update and Delete record from MySQL
  8.   Laravel 6 Update Query using Eloquent Example
  9.   Laravel 6 Traits Example Tutorial - The PHP Framework
  10.   Automatically Refresh/Reload Page using VueJS Example

Leave a Reply

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