Laravel provides a built-in feature that you can use: Request::is().
From the API docs :
Determine if the current request URI matches the pattern.
You use like this:
Request::is('about');
<a href="about" @if(Request::is('about')) class="active" @endif>
You can write a helper function to take care of this:
function isActive($path, $class = 'active')
{
return (Request::is($path)) ? $class : '';
}
helpers.php app composer.json :
"autoload": {
"files": [
"app/helpers.php"
]
},
, composer dump-autoload .
, , :
<a href="about" class="{{ isActive('about') }}">About</a>