Laravel Dynamic Active Class Menu

Today, We want to share with you Laravel Dynamic Active Class Menu.In this post we will show you Laravel 5.7 Add active class to main menu, hear for Getting a menu item to be active dynamically using Laravel 5.7 we will give you demo and example for implement.In this post, we will learn about Dynamically Add Active Classes To Nav With PHP Laravel 5.7 and Bootstrap with an example.

Laravel Dynamic Active Class Menu

There are the Following The simple About Laravel Dynamic Active Class Menu Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to add active class in menu using Laravel 5.7, so the some laravel 5.7 active menu item for this example is following below.

Also Read :  Laravel Add active class to Nav Menu System

Laravel Dynamic Active menu

 <ul class="nav nav-pills pull-right">
    <li class="{{ Request::is('/') ? 'active' : '' }}">
        <a href="{{ url('/') }}">Home</a>
    <li class="{{ Request::is('contact') ? 'active' : '' }}">
        <a href="{{ url('contact') }}">Contact Us</a>
    <li class="{{ Request::is('auth/signin') ? 'active' : '' }}">
        <a href="{{ url('auth/signin') }}">Login</a>

Laravel 5.5 active menu item using request

<ul class="nav nav-second-level">
    <li class="{{ Request::segment(1) === 'examples' ? 'active' : null }}">
        <a href="{{ url('examples' )}}" ></i> examples</a>
    <li class="{{ Request::segment(1) === 'teams' ? 'active' : null }}">
        <a href="{{url('teams')}}"> teams</a>
    <li class="{{ Request::segment(1) === 'members' ? 'active' : null }}">
        <a href="{{url('members')}}"> members</a>

Laravel active menu item for url included parameters

<li class="{{ request()->is('sites/*/edit') ? 'active' : '' }}"
<a href="#" class="nav-link {{ request()->is('employee*') ? 'active' : '' }}">employee</a>

Handling active menu item in Laravel 5

Put this in your helper file:

Also Read :  Multiple WHERE conditions in Laravel Example

function set_active( $route ) {
    if( is_array( $route ) ){
        return in_array(Request::path(), $route) ? 'active' : '';
    return Request::path() == $route ? 'active' : '';


<li class = "{{ set_active('member/employee') }}">
    <a href="{{ url('/member/employee/') }}">employee</a>

Laravel Nave Active Menu Multi-level:

<li class="{{ set_active(['member/items', Request::is('member/auction/*'), 'member/templates']) }}">
        <li class = "{{ set_active('member/item') }}">
            <a href="{{ url('/member/item') }}">All</a>
        <li class = "{{ set_active('member/item/create') }}">
            <a href="{{ URL::to('/member/item/create') }}">Add New</a>
        <li class = "{{ set_active('member/templates') }}">
            <a href="{{ URL::to('/member/templates') }}">templates</a>

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 Dynamic Active Class Menu.
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.