PHPackages                             watson/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. watson/active

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

watson/active
=============

Laravel helper for recognising the current route, controller and action

7.3.0(2mo ago)3253.6M—8.1%18[3 issues](https://github.com/dwightwatson/active/issues)13MITPHPPHP ^8.2CI passing

Since Mar 6Pushed 2mo ago8 watchersCompare

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

READMEChangelogDependencies (12)Versions (35)Used By (13)

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

[](#active-for-laravel)

[![Build Status](https://camo.githubusercontent.com/b1a1bec105bd54eb7bc33a31f9ff985c60d300008ab46211a6e7915e1f25aed1/68747470733a2f2f7472617669732d63692e6f72672f647769676874776174736f6e2f6163746976652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/dwightwatson/active)[![Total Downloads](https://camo.githubusercontent.com/a487114afd9c2ef3e8c8f2c2a008060d45d8339ec7f0e23b610fe8950e3bff41/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f6163746976652f646f776e6c6f6164732e737667)](https://packagist.org/packages/watson/active)[![Latest Stable Version](https://camo.githubusercontent.com/2b260eafc86b8102637ac7ea5fbe19fb657dc41a947aecedec2a3934e0600d7c/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f6163746976652f762f737461626c652e737667)](https://packagist.org/packages/watson/active)[![Latest Unstable Version](https://camo.githubusercontent.com/1cdd015abd4f6b1d340cef253def2595cefbe9bda2ef9d0ddc844d087ac1fc9a/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f6163746976652f762f756e737461626c652e737667)](https://packagist.org/packages/watson/active)[![License](https://camo.githubusercontent.com/e2e5e58c60d0b40a40b317093f5d04580531d82bbe2d0228e8314e5fbe0388dd/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f6163746976652f6c6963656e73652e737667)](https://packagist.org/packages/watson/active)[![Buy us a tree](https://camo.githubusercontent.com/130148911f548b001b2ac68a32c0a06559977ca60ada3bf480c72ae4ea093175/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e)](https://plant.treeware.earth/dwightwatson/active)

Active is a helper package for Laravel that makes it easy to recognize the current path or route, useful for adding 'active' classes (like those used in the Boostrap framework) and performing other actions only when a certain route is active. It also includes helpers for retrieving the current controller and action names.

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

[](#installation)

First, simply require the package through Composer.

```
composer require watson/active
```

**Using Laravel 5.1? The latest version of the package that will work for you is 2.0.4.**

Next, add the service provider in your `config/app.php` file.

`Watson\Active\ActiveServiceProvider::class`

If you'd like to use the Facade instead of the helper functions, add it to the `aliases` array.

`'Active' => Watson\Active\Facades\Active::class`

Using Active
------------

[](#using-active)

### Helper functions

[](#helper-functions)

Active ships with a couple of helper functions which make it easy to use without the facade or creating an instance of your own.

```
active()
is_active()
```

### Using `active()`

[](#using-active-1)

You pass an array of routes or paths you want to see are the current page, and if any match this function will return the string `active`, for Bootstrap. Alternatively, you can pass a custom return string as the second argument.

```
active(['login', 'users/*', 'posts.*', 'pages.contact']); // Returns 'active' if the current route matches any path or route name.

active(['login', 'logout'], 'active-class'); // Returns 'active-class' if the current route is 'login' or 'logout'.

active(['login', 'logout'], 'active-class', 'fallback-class'); // Returns 'fallback-class' if the current route is not 'login' or 'logout'.
```

In the first example, the function will return the string `active` if the current path is `login`, starts with `users/` or if the name of the current route is `posts.create`.

Do note that a number of argument types are provided: you can use a path string, you can use a path string with a wildcard (using the `*`) and you can also use named routes.

You can use this function with your links to give them an active state.

```
All posts
```

You can also provide certain paths or routes to be exluded when being considered.

```
active(['pages/*', 'not:pages/contact'])

active(['pages.*', 'not:pages.contact'])
```

### Using `is_active()`

[](#using-is_active)

This works much the same as `active()`, you can pass the paths and routes to it but instead it will return a boolean if the current page matches.

```
@if (is_active('posts/*'))
    You're looking at a blog post!
@endif
```

### Additional helpers

[](#additional-helpers)

Two additional functions are provided to get the current controller and action, if your routing is being handled by a controller for a request. These functions will return the lowercase controller/action name, without the method of the request. Here is an example for a request that is routed to `FooController@getBar':

```
$controller = controller_name(); // foo

$action = action_name(); // bar
```

Licence
-------

[](#licence)

Active for Laravel is 100% free and open-source, under the [MIT license](LICENSE.txt). Use it however you want.

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/dwightwatson/active) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance88

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community33

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 73.7% 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 ~137 days

Recently: every ~378 days

Total

33

Last Release

61d ago

Major Versions

2.0.6 → 3.0.02018-09-07

3.1.0 → 4.0.02019-09-03

4.0.0 → 5.0.02020-03-03

5.0.0 → 6.0.02020-09-09

6.1.0 → 7.0.02023-02-15

PHP version history (10 changes)1.0.0PHP &gt;=5.3.0

1.3.0PHP &gt;=5.4.0

2.0.1PHP &gt;=5.5.0

3.0.0PHP &gt;=7.0

3.1.0PHP &gt;=7.2

6.0.0PHP ^7.3

6.0.1PHP ^7.3|^8.0

6.1.0PHP ^8.0

7.0.0PHP ^8.1

7.1.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1100408?v=4)[Dwight Watson](/maintainers/dwightwatson)[@dwightwatson](https://github.com/dwightwatson)

---

Top Contributors

[![dwightwatson](https://avatars.githubusercontent.com/u/1100408?v=4)](https://github.com/dwightwatson "dwightwatson (70 commits)")[![poldixd](https://avatars.githubusercontent.com/u/695449?v=4)](https://github.com/poldixd "poldixd (7 commits)")[![tabuna](https://avatars.githubusercontent.com/u/5102591?v=4)](https://github.com/tabuna "tabuna (7 commits)")[![daikazu](https://avatars.githubusercontent.com/u/4039367?v=4)](https://github.com/daikazu "daikazu (2 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (2 commits)")[![josephMG](https://avatars.githubusercontent.com/u/6859129?v=4)](https://github.com/josephMG "josephMG (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![georgeboot](https://avatars.githubusercontent.com/u/884482?v=4)](https://github.com/georgeboot "georgeboot (1 commits)")[![Propaganistas](https://avatars.githubusercontent.com/u/6680176?v=4)](https://github.com/Propaganistas "Propaganistas (1 commits)")[![robinvdvleuten](https://avatars.githubusercontent.com/u/238295?v=4)](https://github.com/robinvdvleuten "robinvdvleuten (1 commits)")[![gbuckingham89](https://avatars.githubusercontent.com/u/1455253?v=4)](https://github.com/gbuckingham89 "gbuckingham89 (1 commits)")[![jamesmills](https://avatars.githubusercontent.com/u/557096?v=4)](https://github.com/jamesmills "jamesmills (1 commits)")

---

Tags

laravelphplaravelroutingactive

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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