Created
January 8, 2018 20:54
-
-
Save mdestafadilah/630bcd4107fc766d5d0c25a2bd9dfcfb to your computer and use it in GitHub Desktop.
Class Active Path Menu di Laravel 5.4
This file contains hidden or 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
/** | |
* 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