Skip to content

Instantly share code, notes, and snippets.

@mdestafadilah
Created January 8, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdestafadilah/630bcd4107fc766d5d0c25a2bd9dfcfb to your computer and use it in GitHub Desktop.
Save mdestafadilah/630bcd4107fc766d5d0c25a2bd9dfcfb to your computer and use it in GitHub Desktop.
Class Active Path Menu di Laravel 5.4
/**
* Checks if a given route is active, if so return a class.
*
* class="{!! classActivePath('order') !!}"
* class="{!! classActivePath('order.index') !!}"
*
* @return path
* @source https://laracasts.com/discuss/channels/general-discussion/best-practice-for-handling-active-menu-item-in-l5/replies/117049
*/
if (!function_exists('classActivePath')) {
function classActivePath($path)
{
$path = explode('.', $path);
$segment = 1;
foreach($path as $p) {
if((request()->segment($segment) == $p) == false) {
return '';
}
$segment++;
}
return ' active';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment