PHPackages                             codinglabsau/laravel-feature-flags - 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. codinglabsau/laravel-feature-flags

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

codinglabsau/laravel-feature-flags
==================================

Dynamic feature flags for laravel.

v1.6.0(2mo ago)3891.0k↓68.4%[2 PRs](https://github.com/codinglabsau/laravel-feature-flags/pulls)MITPHPPHP ^8.3CI passing

Since Mar 31Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/codinglabsau/laravel-feature-flags)[ Packagist](https://packagist.org/packages/codinglabsau/laravel-feature-flags)[ Docs](https://github.com/codinglabsau/laravel-feature-flags)[ RSS](/packages/codinglabsau-laravel-feature-flags/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (12)Versions (16)Used By (0)

Dynamic Feature Flags for Laravel
=================================

[](#dynamic-feature-flags-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1d8f5dae6a88d2bbddf8a63f6526acc8535f9ec34c151f60576c2b61238c4ee3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64696e676c61627361752f6c61726176656c2d666561747572652d666c6167732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codinglabsau/laravel-feature-flags)[![Test](https://github.com/codinglabsau/laravel-feature-flags/actions/workflows/run-tests.yml/badge.svg)](https://github.com/codinglabsau/laravel-feature-flags/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/b29140afb204542b46b5a3692efba81118c8788fc49b123b56995ad872ab7338/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64696e676c61627361752f6c61726176656c2d666561747572652d666c6167732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codinglabsau/laravel-feature-flags)

Laravel Feature Flags allows instant, zero-deployment toggling of application features.

The state of each feature flag can be checked from anywhere in the application code (including via a `@feature('name')` blade directive) to determine whether the conditions you set have been met to enable the feature.

Each feature can be in one of three states:

- On: enabled for everyone
- Off: disabled for everyone
- Dynamic: evaluated according to a feature-specific closure (with a fallback option)

---

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

[](#installation)

### Install With Composer

[](#install-with-composer)

```
composer require codinglabsau/laravel-feature-flags
```

### Database Migrations

[](#database-migrations)

```
php artisan vendor:publish --tag="feature-flags-migrations"
php artisan migrate
```

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --tag="feature-flags-config"
```

### Set Your Cache Store

[](#set-your-cache-store)

This package caches the state of features to reduce redundant database queries. The cache is expired whenever the feature state changes.

By default, this package will use the default cache configured in your application.

If you wish to change to a different cache driver, update your `.env`:

```
FEATURES_CACHE_STORE=file

```

Usage
-----

[](#usage)

Create a new feature in the database and set the initial state:

```
use Codinglabs\FeatureFlags\Models\Feature;
use Codinglabs\FeatureFlags\Enums\FeatureState;

Feature::create([
    'name' => 'search-v2',
    'state' => FeatureState::on()
]);
```

Its recommended that you seed the features to your database before a new deployment or as soon as possible after a deployment.

### Check If A Feature Is Enabled

[](#check-if-a-feature-is-enabled)

#### Blade View

[](#blade-view)

Use the `@feature` blade directive anywhere in your view files.

```
@feature('search-v2')
    // new search goes here
@else
    // legacy search here
@endfeature
```

#### In Your Code

[](#in-your-code)

Use the `FeatureFlag` facade to conveniently check the state of a feature in your app code.

```
use Codinglabs\FeatureFlags\Facades\FeatureFlag;

if (FeatureFlag::isOn('search-v2')) {
    // new feature code
} else {
    // old code
}
```

#### Middleware

[](#middleware)

Register `feature` as a route middleware in your HTTP Kernel to protect routes. A 404 response will be returned if the feature does not resolve to the on state.

```
// app/Http/Kernel.php
protected $routeMiddleware = [
    // ...
    'feature' => \Codinglabs\FeatureFlags\Middleware\VerifyFeatureIsOn::class,
];

// routes/web.php
Route::get('search-v2', \App\Http\Controllers\SearchV2Controller::class)->middleware('feature:search-v2');
```

### Check If A Feature Is Disabled

[](#check-if-a-feature-is-disabled)

#### Blade View

[](#blade-view-1)

```
@unlessfeature('search-v2')
    // no new features for you
@endfeature
```

#### In Your Code

[](#in-your-code-1)

```
use Codinglabs\FeatureFlags\Facades\FeatureFlag;

if (FeatureFlag::isOff('search-v2')) {
    // no new features for you
}
```

### Get The Underlying Current State

[](#get-the-underlying-current-state)

If you want to know what the underlying `FeatureState` value is:

```
use Codinglabs\FeatureFlags\Facades\FeatureFlag;

// value from Codinglabs\FeatureFlags\Enums\FeatureState
$featureState = FeatureFlag::getState('search-v2');
```

### Updating Feature State

[](#updating-feature-state)

To change the state of a feature you can call the following methods:

```
use Codinglabs\FeatureFlags\Facades\FeatureFlag;

FeatureFlag::turnOn('search-v2');
FeatureFlag::turnOff('search-v2');
FeatureFlag::makeDynamic('search-v2');
```

Alternatively you can set the state directly by passing a feature state enum:

```
FeatureFlag::updateFeatureState('search-v2', FeatureState::on())
```

It is recommended that you only update a features state using the above methods as it will take care of flushing the cache and dispatching the feature updated event:

```
\Codinglabs\FeatureFlags\Events\FeatureUpdatedEvent::class
```

You should listen for the `FeatureUpdatedEvent` event if you have any downstream implications when a feature state is updated, such as invalidating any cached items that are referenced in dynamic handlers.

---

Advanced Usage
--------------

[](#advanced-usage)

### Dynamic Features

[](#dynamic-features)

A dynamic handler can be defined in the `boot()` method of your `AppServiceProvider`:

```
use Codinglabs\FeatureFlags\Facades\FeatureFlag;

FeatureFlag::registerDynamicHandler('search-v2', function ($feature, $request) {
    return $request->user() && $request->user()->hasRole('Tester');
});
```

Dynamic handlers will only be called when a feature is in the `dynamic` state. This will allow you to define custom rules around whether that feature is enabled like in the example above where the user can only access the feature if they have a tester role.

Each handler is provided with the features name and current request as arguments and must return a boolean value.

### Default Handler For Dynamic Features

[](#default-handler-for-dynamic-features)

You may also define a default handler which will be the catch-all handler for features that don't have an explicit handler defined for them:

```
FeatureFlag::registerDefaultDynamicHandler(function ($feature, $request) {
    return $request->user() && $request->user()->hasRole('Tester');
});
```

An explicit handler defined using `registerDynamicHandler()` will take precedence over the default handler. If neither a default nor explicit handler has been defined then the feature will resolve to `off` by default.

### Handle Missing Features

[](#handle-missing-features)

Features must exist in the database otherwise a `MissingFeatureException` will be thrown. This behaviour can be turned off by explicitly handling cases where a feature doesn't exist:

```
FeatureFlag::handleMissingFeaturesWith(function ($feature) {
    // log or report this somewhere...
})
```

If a handler for missing features has been defined then an exception will **not** be thrown and the feature will resolve to `off`.

### Using Your Own Model

[](#using-your-own-model)

To use your own model, update the config and replace the existing reference with your own model:

```
// app/config/feature-flags.php

'feature_model' => \App\Models\Feature::class,
```

Make sure to also cast the state column to a feature state enum using the `FeatureStateCast`:

```
// app/Models/Feature.php

use Codinglabs\FeatureFlags\Casts\FeatureStateCast;

protected $casts = [
    'state' => FeatureStateCast::class
];
```

### Sharing features with UI (Inertiajs example)

[](#sharing-features-with-ui-inertiajs-example)

```
// app/Middleware/HandleInertiaRequest.php

use Codinglabs\FeatureFlags\FeatureFlags;
use Codinglabs\FeatureFlags\Models\Feature;

Inertia::share([
    'features' => function () {
        return Feature::all()
            ->filter(fn ($feature) => FeatureFlags::isOn($feature['name']))
            ->pluck('name');
    }
]);
```

```
// app.js

Vue.mixin({
  methods: {
    hasFeature: function(feature) {
      return this.$page.features.includes(feature)
    }
  }
})
```

```

Some cool new feature
```

Testing
-------

[](#testing)

```
composer test
```

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jonathan Louw](https://github.com/JonathanLouw)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

57

—

FairBetter than 97% of packages

Maintenance85

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 70.9% 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 ~147 days

Recently: every ~331 days

Total

11

Last Release

80d ago

PHP version history (3 changes)v1.0.0PHP ^8.0

v1.4.0PHP ^8.1

v1.5.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1127412?v=4)[Steve Thomas](/maintainers/stevethomas)[@stevethomas](https://github.com/stevethomas)

---

Top Contributors

[![stevethomas](https://avatars.githubusercontent.com/u/1127412?v=4)](https://github.com/stevethomas "stevethomas (39 commits)")[![JonathanLouw](https://avatars.githubusercontent.com/u/14814040?v=4)](https://github.com/JonathanLouw "JonathanLouw (16 commits)")

---

Tags

feature-flagslaravellaravelflagsfeatureCodinglabslaravel-feature-flags

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/codinglabsau-laravel-feature-flags/health.svg)

```
[![Health](https://phpackages.com/badges/codinglabsau-laravel-feature-flags/health.svg)](https://phpackages.com/packages/codinglabsau-laravel-feature-flags)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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