Last active
May 2, 2016 21:25
-
-
Save kel/a264b3fd2f1d9caf084eb24784470f2a to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Adds active to the class if current path | |
* equals passed path. Allows custom | |
* classes as well. | |
* | |
* @param $paths | |
* @param null $classes | |
* @return string | |
*/ | |
function active_class_path($paths, $classes = null) | |
{ | |
foreach ((array) $paths as $path) { | |
if (request()->is($path)) { | |
return 'class="' . ($classes ? $classes . ' ' : '') . 'active"'; | |
} | |
} | |
return $classes ? 'class="' . $classes . '"' : ''; | |
} |
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
<ul class="menu"> | |
<li><a href="{{ url('articles') }}" {!! active_class_path(['articles', 'a/*']) !!}>Articles</a></li> | |
<li><a href="{{ url('dashboard') }}" {!! active_class_path('dashboard', 'additional classes here') !!}>Dashboard</a></li> | |
<li><a href="{{ url('dashboard/users') }}" {!! active_class_path('dashboard/users') !!}>Users</a></li> | |
<li><a href="{{ url('dashboard/settings') }}" {!! active_class_path('dashboard/settings') !!}>Site settings</a></li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment