PHPackages                             harryjhonny/laravel-feature-flag - 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. harryjhonny/laravel-feature-flag

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

harryjhonny/laravel-feature-flag
================================

A Laravel package for handling feature flags

1.0.0(6y ago)02MITPHPPHP ^7.2

Since Dec 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/harryjhonny/laravel-feature-flag)[ Packagist](https://packagist.org/packages/harryjhonny/laravel-feature-flag)[ Docs](https://github.com/harryjhonny/laravel-feature-flag)[ RSS](/packages/harryjhonny-laravel-feature-flag/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

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

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

A Feature flag is sometimes also referred to as a feature toggle or feature switch. Ultimately it's a coding strategy to be used along with source control to make it easier to continuous integrate and continuous deployment. The idea of the flags works by essentially safe guarding sections of code from executing if a feature flag isn't in a switched on state.

This package aims to make implementing such flags across your application a great deal easier by providing solutions that work with not only your code but your routes, blade files, task scheduling and validations.

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

[](#installation)

You can install the package via composer:

```
composer require harryjhonny/laravel-feature-flag
```

Once installed you should publish the config with the following command.

```
php artisan vendor:publish --provider=Harryjhonny\\FeatureFlags\\FeatureFlagsServiceProvider --tag=config
```

You can customise the `features.php` config in a number of ways. By default four storage drivers for the feature flags are provided, config, database, redis and chain. the first three are pretty straight forward but the chain is essentially a composite that allows you to store across all three. For example you might want to query a feature that's hardcoded in the config. If it does not exist it will then go on to check redis. If it's not stored there, then it'll check the database. Afterwards it can update the other sources to improve flag checking times.

To use the Database driver you will need to add the migration. You can do this by using the publish command.

```
php artisan vendor:publish --tag=features-migration
```

Everything is enabled by default but if you want to turn off several features add the following method calls to the boot method of `app/Providers/AppServiceProvider.php` in your project.

```
Features::noBlade();
Features::noScheduling();
Features::noValidations();
Features::noCommands();
```

To install the middleware you'll have to add it to your `$routeMiddleware` inside `app/Http/Kernel.php` file.

```
protected $routeMiddleware = [
    'feature' => \Harryjhonny\FeatureFlags\Middleware\FeatureFlagState::class,
];
```

Usage
-----

[](#usage)

### Checking feature accessibility

[](#checking-feature-accessibility)

You can use the accessible method to check if a feature is on or off.

```
Features::accessible('my-feature') // returns true or false
```

### Blade Views

[](#blade-views)

the `@feature` blade directive is a simple `@if` shortcut to hide or display certain parts of the view depending on the state of the feature. A second argument flips the state e.g. it will display the contents of the if statement if the feature is off.

```
@feature('my-feature')
    Your feature flag is turned on.
@endfeature

@feature('my-feature', false)
    Your feature flag is turned off.
@endfeature
```

### Routing Middleware

[](#routing-middleware)

The middleware will cause routes to be blocked if the specified feature does not have the correct state.

```
Route::get('/', 'SomeController@get')->middleware('feature:my-feature')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,on')
Route::get('/', 'SomeController@get')->middleware('feature:my-feature,off,404')
```

### Validation Rules

[](#validation-rules)

Fields can be marked as required depending on if the feature is in a particular state.

```
Validator::make([
    'name' => 'Peter'
    'place' => 'England',
    'email' => 'peter.fox@harryjhonny.co'
], [
    'name' => 'requiredWithFeature:my-feature' // required
    'place' => 'requiredWithFeature:my-feature,on' // required
    'email => 'requiredWithFeature:my-feature,off' // not required
]);
```

### Task Scheduling

[](#task-scheduling)

Using the following will determine if a task will run on schedule depending on the state of the feature.

```
$schedule->command('emails:send Peter --force')
    ->skipWithFeature('my-feature')

$schedule->command('emails:send Peter --force')
    ->skipWithoutFeature('my-other-feature')
```

### Artisan Commands

[](#artisan-commands)

You may run the following commands to toggle the on or off state of the feature.

```
php artisan feature:on my-feature

php artisan feature:off my-feature
```

To find out the current state of the feature within the context of a console command, run the following:

```
php artisan feature:state my-feature
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

2333d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/29c04ac491de4dfa365a167722f319c98a0bd78eea74f91b64a5dfefd1d319dd?d=identicon)[harryjhonny](/maintainers/harryjhonny)

---

Top Contributors

[![hari-ibuild](https://avatars.githubusercontent.com/u/102937103?v=4)](https://github.com/hari-ibuild "hari-ibuild (1 commits)")

---

Tags

harryjhonnylaravel-feature-flag

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/harryjhonny-laravel-feature-flag/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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