Created
April 16, 2017 06:01
-
-
Save muhx/b4e5f11e5d8600049a61fb92755fd93d to your computer and use it in GitHub Desktop.
Laravel 5.4 Active Route Helper in app/Http/helpers.php
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 | |
/* | |
|-------------------------------------------------------------------------- | |
| Detect Active Route | |
|-------------------------------------------------------------------------- | |
| | |
| Compare given route with current route and return output if they match. | |
| Very useful for navigation, marking if the link is active. | |
| | |
*/ | |
function isActiveRoute($route, $output = "active") | |
{ | |
if (Route::currentRouteName() == $route) return $output; | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Detect Active Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Compare given routes with current route and return output if they match. | |
| Very useful for navigation, marking if the link is active. | |
| | |
*/ | |
function areActiveRoutes(Array $routes, $output = "active") | |
{ | |
foreach ($routes as $route) | |
{ | |
if (Route::currentRouteName() == $route) return $output; | |
} | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Readme | |
|-------------------------------------------------------------------------- | |
| | |
| Set composer json to load the file, add this block: | |
| "files": [ | |
| "app/Http/helpers.php" | |
| ] | |
| Then run composer dump-autoload | |
| | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment