Skip to content

Instantly share code, notes, and snippets.

@muhx
Created April 16, 2017 06:01
Show Gist options
  • Save muhx/b4e5f11e5d8600049a61fb92755fd93d to your computer and use it in GitHub Desktop.
Save muhx/b4e5f11e5d8600049a61fb92755fd93d to your computer and use it in GitHub Desktop.
Laravel 5.4 Active Route Helper in app/Http/helpers.php
<?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