stevebauman/active

An Active link helper for outputting classes for the users current route.

Installs: 1 655

Dependents: 3

Suggesters: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:package

v1.0.1 2016-02-09 03:23 UTC

README

An active HTML class helper that echo's strings based on the current route.

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

🚨 Abandoned 🚨

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.

Installation

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!

Usage

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>

Setting a different output

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>