PHPackages                             sebastienheyd/active - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sebastienheyd/active

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sebastienheyd/active
====================

Helper class for Laravel to get the active class based on the current route

1.3.1(1mo ago)014.8k↓31.1%11MITPHPPHP &gt;=7.2.5CI passing

Since Mar 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/sebastienheyd/active)[ Packagist](https://packagist.org/packages/sebastienheyd/active)[ RSS](/packages/sebastienheyd-active/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (10)Versions (6)Used By (1)

Active for Laravel
==================

[](#active-for-laravel)

[![tests](https://github.com/sebastienheyd/active/actions/workflows/tests.yml/badge.svg)](https://github.com/sebastienheyd/active/actions/workflows/tests.yml)[![Laravel](https://camo.githubusercontent.com/b899b3a71d5571946cbeee11209119f3c4db1670f4ae88216f958684b7fba732/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e7825323025453225383625393225323031332e782d7265643f6c6f676f3d4c61726176656c267374796c653d666c61742d737175617265)](https://laravel.com/)[![Packagist](https://camo.githubusercontent.com/17b15f68bfef3c945765d4485e346f0be0de335db2df15b800b8e7d0c0d6c2ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73656261737469656e686579642f6163746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sebastienheyd/active)[![Nb downloads](https://camo.githubusercontent.com/eee18f7c37951b1d4f92b8dedc93acb7833d67f5b9ced8da70b5ebd2319cbc72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73656261737469656e686579642f6163746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sebastienheyd/active)[![License](https://camo.githubusercontent.com/7adf69e530752ed0ed04e341c6db5f295be4fbf7046ce7e0fa55f380e2e8ce3e/68747470733a2f2f706f7365722e707567782e6f72672f686965752d6c652f6163746976652f6c6963656e73652e737667)](LICENSE)

Helper class for Laravel to get the active class based on the current url.

This project is based on [hieu-le/active](https://github.com/letrunghieu/active)

Installation
------------

[](#installation)

Require this package as your dependencies:

```
composer require sebastienheyd/active

```

Configuration (optional)
------------------------

[](#configuration-optional)

You can define another default class name instead of `active` by editing the `active.php` configuration file.

To publish the configuration file you can use the following command:

```
php artisan vendor:publish --tag=active

```

Usage
-----

[](#usage)

- Use the alias: `Active::getClassIf($condition, $activeClass = 'active', $inactiveClass = '')`
- Use the application container: `app('active')->getClassIf($condition, $activeClass = 'active', $inactiveClass = '')`
- Use the helper function: `active_class($condition, $activeClass = 'active', $inactiveClass = '')`

Explanation: if `$condition` is true, the value of `$activeClass` is returned, otherwise the value of `$inactiveClass` is returned.

```
active_class(true); // 'active' (default value set in the configuration file)
active_class(false); // ''
active_class(if_uri([$currentUri]), 'selected'); // 'selected'
active_class(if_uri_pattern([$pattern1, $pattern2]), 'active', 'other'); // 'other'
```

### Check the current URI

[](#check-the-current-uri)

All of checking methods return boolean result (`true` or `false`). You can use the result in the condition of `active_class` or write your own expression.

### Check the whole URI

[](#check-the-whole-uri)

Usage:

- Use the alias: `Active::checkUri(array $uris)`
- Use the application container: `app('active')->checkUri(array $uris)`
- Use the helper function: `if_uri(array $uris)`

Explanation: you give an array of URI, the package will return true if the current URI is in your array. Remember that an URI does not begin with the slash (`/`) except the root.

### Check the URI with some patterns

[](#check-the-uri-with-some-patterns)

Usage:

- Use the alias: `Active::checkUriPattern(array $patterns)`
- Use the application container: `app('active')->checkUriPattern(array $patterns)`
- Use the helper function: `if_uri_pattern(array $patterns)`

Explanation: you give an array of patterns, the package will return true if the current URI matches one of the given pattern. Asterisks may be used in the patterns to indicate wildcards.

### Check the query string

[](#check-the-query-string)

Usage:

- Use the alias: `Active::checkQuery($key, $value)`
- Use the application container: `app('active')->checkQuery($key, $value)`
- Use the helper function: `if_query($key, $value)`

Explanation: the package will return true if one of the following condition is true:

- The current query string contains a parameter named `$key` with any value and the value of `$value` is `false`.
- The current query string does not contain a parameter named `$key` and the value of `$value` is `null`.
- The current query string contains a parameter named `$key` whose value is a string equals to `$value`.
- The current query string contains a parameter named `$key` whose value is an array that contain the `$value`.

```
// the current query string is ?x=1&y[0]=a&y[1]=b

if_query('x', null); // true
if_query('x', 1); // true
if_query('x', 2); // false
if_query('y', 'a'); // true
if_query('y', 'c'); // false
if_query('z', null); // false
```

Check the current route
-----------------------

[](#check-the-current-route)

### Check the exact route name

[](#check-the-exact-route-name)

Usage:

- Use the alias: `Active::checkRoute(array $routes)`
- Use the application container: `app('active')->checkRoute(array $routes)`
- Use the helper function: `if_route(array $routes)`

Explanation: you give an array of route names, the package will return true if the name of the current route (which can be null) is in your array.

### Check the route name with some patterns

[](#check-the-route-name-with-some-patterns)

Usage:

- Use the alias: `Active::checkRoutePattern(array $patterns)`
- Use the application container: `app('active')->checkRoutePattern(array $patterns)`
- Use the helper function: `if_route_pattern(array $patterns)`

Explanation: you give an array of patterns, the package will return true if the name of the current route (which can be null) matches one of the given pattern. Asterisks may be used in the patterns to indicate wildcards.

### Check the route parameter value

[](#check-the-route-parameter-value)

Usage:

- Use the alias: `Active::checkRouteParam($key, $value)`
- Use the application container: `app('active')->checkRouteParam($key, $value)`
- Use the helper function: `if_route_param($key, $value)`

Explanation: the package will return `true` if one of the following condition is true:

- The current route contains a parameter named `$key` whose value is `$value`.
- The current route does not contain a parameter named `$key` and the value of `$value` is null.

Read more about route parameter in the [Laravel documentation](https://laravel.com/docs/routing#route-parameters).

Get the current values
----------------------

[](#get-the-current-values)

### Get the current action

[](#get-the-current-action)

Usage:

- Use the alias: `Active::getAction()`
- Use the application container: `app('active')->getAction()`
- Use the helper function: `current_action()`

Explanation: if the current route is bound to a class method, the result will be a string like `App\Http\Controllers\YourController@yourMethod`. If the route is bound to a closure, the result will be the `Closure` string.

### Get the current controller class

[](#get-the-current-controller-class)

Usage:

- Use the alias: `Active::getController()`
- Use the application container: `app('active')->getController()`
- Use the helper function: `current_controller()`

Explanation: if the current route is bound to a class method, the result will be the full qualified class name of the controller class, like `App\Http\Controllers\YourController`. If the route is bound to a closure, the result will be the `Closure` string.

### Get the current controller method

[](#get-the-current-controller-method)

Usage:

- Use the alias: `Active::getMethod()`
- Use the application container: `app('active')->getMethod()`
- Use the helper function: `current_method()`

Explanation: if the current route is bound to a class method, the result will be the name of the controller method. like `yourMethod`. If the route is bound to a closure, the result will be the empty string.

Example
-------

[](#example)

The example below illustrate the usage of this package in a sidebar with [Bootstrap list group](https://getbootstrap.com/docs/5.3/components/list-group/) :

```

        Active users

        Inactive users

        Add users

```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~274 days

Total

5

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9734baf9cf5aaf3f2243aa8a57e23e59f95b70f0bb30c2628f9e88bc76dc3c1a?d=identicon)[sebastienheyd](/maintainers/sebastienheyd)

---

Top Contributors

[![sebastienheyd](https://avatars.githubusercontent.com/u/5470423?v=4)](https://github.com/sebastienheyd "sebastienheyd (10 commits)")

---

Tags

laravelroutingactive

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/sebastienheyd-active/health.svg)

```
[![Health](https://phpackages.com/badges/sebastienheyd-active/health.svg)](https://phpackages.com/packages/sebastienheyd-active)
```

###  Alternatives

[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
