Solution:
Laravel provides a built-in function you can use: Request::is()
.
From the API docs:
Determine if the current request URI matches a pattern.
You use is like this:
Request::is('about'); // returns a boolean
<a href="about" @if(Request::is('about')) class="active" @endif>
You could write a helper function to take care of it:
function isActive($path, $class = 'active')
{
return (Request::is($path)) ? $class : '';
}
Put it in a file called helpers.php
in your app
directory and include it in the autoload-part of your composer.json
like this:
"autoload": {
"files": [
"app/helpers.php"
]
},
Maybe you need to do a composer dump-autoload
in your terminal.
And finally use it like this:
<a href="about" class="{{ isActive('about') }}">About</a>