stevebauman/active

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

Installs: 1 849

Dependents: 1

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 1

Open Issues: 0

Type:package

v2.0.0 2021-01-05 22:38 UTC

This package is auto-updated.

Last update: 2024-04-06 06:00:14 UTC


README

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

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);

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/` -->
<a
    class="btn btn-success {{ active()->route('products.index') }}"
    href="{{ route('products.index') }}">
        Products
</a>
<!-- `active` will be displayed when you visit `products/` 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>