Probably one of the most common operation on every website is to assign “active” CSS class to the menu item which is currently opened. There are quite a few ways to detect that status, let’s review them.
If you are doing using without page refresh then you can do it simply by jquery. But when you click on link page refresh so you have to make something like when page load, i mean using laravel.
However, Laravel 7 provide Request facade and using "Request::is" method we can check url patten and make it active. Here bellow give you easy example and you can simply follow that.
Or you can also use your own custom method to handle active menu item. 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' : '';
}
Usages:
Hope it will help you.
#laravel-6 #active-menu #laravel