An active HTML class helper that echo's strings based on the current route.
This package has been abandoned in favor or Laravel's now default implementation request()->routeIs($pattern)
method.
The above method now exists for any Laravel application that is version 5.4 or greater.
This repository will still remain up on both Packagist and GitHub.
Insert active inside your composer.json
:
"stevebauman/active": "1.0.*"
Insert the service provider in config/app.php
only if you need the configuration file.
\Stevebauman\Active\ActiveServiceProvider::class,
Run composer update
, and you're all set!
This documentation will use the active()
helper.
The default output class is active
, which is the standard bootstrap class for displaying buttons and links in a different
color if they match the current URL.
Output on active routes or route:
<!-- `active` will be displayed when you visit `products/index` -->
<a
class="btn btn-success {{ active()->route('products.index') }}"
href="{{ route('products.index') }}">
Products
</a>
<!-- `active` will be displayed when you visit `products/index` or `products/create` -->
<a
class="btn btn-success {{ active()->routes(['products.index', 'products.create']) }}"
href="{{ route('products.index') }}">
Products
</a>
To output active on any routes below a certain route, use the wildcard (*
) inside your route.
For example:
<!-- `active` will be displayed when you visit any route below `products.` -->
<a
class="btn btn-success {{ active()->route('products.*') }}"
href="{{ route('products.index') }}">
Products
</a>
<!-- `active` will be displayed when you visit any route below `products.`, or `suppliers.` -->
<a
class="btn btn-success {{ active()->routes(['products.*', 'suppliers.*']) }}"
href="{{ route('products.index') }}">
Products
</a>
To set a different output, use the output()
method:
<a
class="btn btn-success {{ active()->output('my-active-class')->route('products.*') }}"
href="{{ route('products.index') }}">
Products
</a>