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.

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

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.

Laravel Dynamic Active menu

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

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>
    <li class="{{ Request::segment(1) === 'teams' ? 'active' : null }}">
        <a href="{{url('teams')}}"> teams</a>
    </li>
    <li class="{{ Request::segment(1) === 'members' ? 'active' : null }}">
        <a href="{{url('members')}}"> members</a>
    </li>                     
</ul>

Laravel active menu item for url included parameters

<li>is('sites/*/edit') ? 'active' : '' }}"
//or
<a href="#">is('employee*') ? 'active' : '' }}">employee</a>

Handling active menu item in Laravel 5

Put this in your helper file:

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

Usage:

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

Laravel Nave Active Menu Multi-level:

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

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


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel Delete Multiple Checkboxes Example
  2.   Bootstrap collapse plus minus sign Examples
  3.   Jquery Restrict only 10 numbers input in textbox
  4.   how to get last inserted id in laravel 6
  5.   PHP multi dimensional array sorting by a column with example
  6.   Laravel Collection Contains Example
  7.   Pure CSS Add active class to hover effects
  8.   Laravel Add active class to Nav Menu System
  9.   MySQL SELECT all records from today using Laravel 6
  10.   Stopping On First Validation Failure in Laravel Bail Rule

Leave a Reply

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