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

sidebar.blade.php

Laravel Add active class to Nav Menu System

Free Download Example - Pakainfo.com

Setp 2: Create Custom Laravel helpers

app/library/helpers.php

<?php
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": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files":["app/library/helpers.php"]
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"extra": {
    "laravel": {
        "dont-discover": [
        ]
    }
},
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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 Pakainfo.com 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.

Leave a Comment