Last active
September 11, 2020 12:59
-
-
Save vitorleonel/e4ba465c62b3e03e3170afe397882f79 to your computer and use it in GitHub Desktop.
[Laravel] function to check if it is the current route and return a specific class for make item is active or no
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('currentRoute')) | |
{ | |
/** | |
* Return class when is current route match passed name. | |
* | |
* @param string $name | |
* @param string $htmlClass | |
* @return string | |
*/ | |
function currentRoute(string $name, string $htmlClass = 'menu__item--actived') : string | |
{ | |
return \Illuminate\Support\Facades\Request::routeIs($name) ? $htmlClass : ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of use:
You pass exactly or partial route name. In partial case, use * after or before. That is, any route that starts with packages returns the class activated for my menu item, in my case.