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

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

friendsofcat/laravel-feature-flag
=================================

Feature Flags for Laravel

4.2.2(3y ago)311.2M↓25.3%7MITPHPPHP ^7.3|^8.0CI failing

Since May 5Pushed 2y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (38)Used By (0)

Feature Flags In Laravel
========================

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

[![CI-CD](https://github.com/friendsofcat/laravel-feature-flag/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/friendsofcat/laravel-feature-flag/actions/workflows/ci-cd.yml)

- [Overview](#overview)
- [Installing](#installing)
- [Usage](#usage)
- [Usage Non Auth](#usage-non-auth)
- [Syncing Flags](#syncing-flags)
- [Example](#example)
- [Testing](#testing)
- [Todo](#todo)

Overview
--------

[](#overview)

You can find a comprehensive blog post about [this library here](https://alfrednutile.info/posts/175). This project is a work in progress.

We are working on using FeatureFlags or Toggles in our applications. For one we are aiming to do all our work on mainline branch at all times so this would be a key coding discipline to use FeatureFlags so we can hide a feature in progress knowing it will not interfere with the application. For example if a hotfix or another feature is ready to go to production we can push that with no worries of the in progress feature.

At the core we use this library [Atriedes/feature](https://github.com/Atriedes/feature) as it has the logic needed to consider common feature flag states eg user, users, on, off, groups, admin, internal, random etc. However, we are also mixing in some nice Laravel [Authorization](https://laravel.com/docs/5.2/authorization) features so you can do things like:

In a blade template:

```
@can('feature-flag', 'add-twitter-field')

@endcan
```

Or in PHP:

```
if (Gate::allows('feature-flag', 'awesome-feature')) {

}
```

```
if (Gate::denies('feature-flag', 'awesome-feature')) {

}
```

If you need to pass your feature flags to a front-end JS framework like Angular or Vue.js, you can do so by using the FeatureFlagsForJavascript::get() static method.

This uses this library  to put this info into the `windows` object, and for Angular the `$window` now you can access it:

```
JavaScript::Put(
            [
                'pusher_public_key' => env('PUSHER_PUBLIC'),
                'feature_flags'     => FeatureFlagsForJavascript::get()
            ]
        );

```

Installing
----------

[](#installing)

Require the package using composer:

```
composer require "friendsofcat/laravel-feature-flag"

```

Add the following to your config/app.php providers array:

```
FriendsOfCat\LaravelFeatureFlags\FeatureFlagsProvider::class,

```

Publish the package migrations:

```
php artisan vendor:publish --provider="FriendsOfCat\LaravelFeatureFlags\FeatureFlagsProvider" --tag='migrations'

```

Then run migration to setup the base table:

```
php artisan migrate

```

This package creates a number of routes. They can be overridden by publishing the views:

```
php artisan vendor:publish --provider="FriendsOfCat\LaravelFeatureFlags\FeatureFlagsProvider" --tag='views'

```

This will then place the files in `resources/vendors/laravel-feature-flags`. Just note that the views `@extends('layouts.default')` so if yours differs you will need to make an adjustment to the published views files.

Next, publish the configuration:

```
php artisan vendor:publish --provider="FriendsOfCat\LaravelFeatureFlags\FeatureFlagsProvider" --tag='config'

```

Important: The routes detault to being projected by the 'auth' middleware but you should check your installation to make sure permissions are acceptable. Middleware settings are configurable in 'config/laravel-feature-flag.php' file.

Make sure to set the `default_view` as well for the layout.

`config/laravel-feature-flag.php`

Your .env

```
LARAVEL_FEATURE_FLAG_VIEW="layouts.default"

```

Usage
-----

[](#usage)

Visit `/admin/feature_flags` to manage features via the UI.

### Checking if a feature flag exists

[](#checking-if-a-feature-flag-exists)

For this you can use the exists() method

```
if(\FriendsOfCat\LaravelFeatureFlags\Feature::exists('see-twitter-field'))
{
  //do something
}

```

### Enable for User Roles

[](#enable-for-user-roles)

You can enable a feature flag for specific user roles, by using the **roles** variant in the configuration form

i.e.

```
{ "roles": ["admin", "dev"]}

```

If you don't have a roles property in your User model, you just need to implement the **FeatureFlagsEnabler** Interface and use **FeatureFlagUserRoleTrait**

```
use FriendsOfCat\LaravelFeatureFlags\FeatureFlagsEnabler;
use FriendsOfCat\LaravelFeatureFlags\FeatureFlagUserRoleTrait;

class User extends Authenticatable implements FeatureFlagsUserRoles
{
    use AuthenticableTrait, FeatureFlagUserRoleTrait;
}

```

### Enable for User Teams

[](#enable-for-user-teams)

You can enable a feature flag for specific user teams, by using the **teams** variant in the configuration form

i.e.

```
{ "teams": ["Team 1", "Team 2"]}

```

If you don't have a teams property in your User model, you just need to implement the **FeatureFlagsEnabler** Interface and use **FeatureFlagUserRoleTrait**

```
use FriendsOfCat\LaravelFeatureFlags\FeatureFlagsEnabler;
use FriendsOfCat\LaravelFeatureFlags\FeatureFlagUserRoleTrait;

class User extends Authenticatable implements FeatureFlagsUserRoles
{
    use AuthenticableTrait, FeatureFlagUserRoleTrait;
}

```

Usage Non Auth
--------------

[](#usage-non-auth)

Sometimes you are not using this at the Auth user level, it is rare for most of our use cases but for non authenticated situations you can just use this

```
if(\FriendsOfCat\LaravelFeatureFlags\Feature::isEnabled('see-twitter-field'))
{
  //do something
}

```

Remember you needed to put this into the database, so it is on or off. You might not have a UI, maybe this is a microservice for example, so just migrate the state into the database for example

```
$feature = new FeatureFlag();
$feature->key = "see-twitter-field";
$feature->variants = "on"; //or "off"
$feature->save();

```

Now when the FeatureFlag Provider instantiates it will set this as the "World" state and you can access it via the isEnabled "on" being true and "off" being false.

Syncing Flags
-------------

[](#syncing-flags)

Feature flags can be synchronised using the provided `feature-flag:sync` command. This will sync flags defined in the [`sync_flags`](https://github.com/friendsofcat/laravel-feature-flag/blob/master/config/laravel-feature-flag.php#L24) configuration in the `laravel-feature-flag.php` config file. The format for this flag configuration is "key =&gt; default value". By default, any flags that are removed will be removed from storage. There is a `--skip-cleanup` flag available to skip this step.

Demo / Example
--------------

[](#demo--example)

If you want to try the demo/example also include the following in your config/app.php providers array:

```
FriendsOfCat\LaravelFeatureFlags\ExampleFeatureProvider::class

```

and then run:

```
php artisan vendor:publish --provider="FriendsOfCat\LaravelFeatureFlags\ExampleFeatureProvider" --tag='migrations'
php artisan migrate

```

It has a rollback to help clean up after.

There is a dummy route called `/admin/feature_flags/example` that you can visit and it will show that it is not on. But if you then go to the admin UI `/admin/feature_flags` you can toggle it on and off.

Testing
-------

[](#testing)

> [Helper Package](https://github.com/orchestral/testbench)

There is the settings page which I do have some Laravel tests for that you can run once the package is installed.

Also if you are trying to test the use of it in your work you can use the helper trait in your test class

```
    use DatabaseTransactions, \FriendsOfCat\LaravelFeatureFlags\FeatureFlagHelper;
```

Then from there factory out your additions and state then reregister the world

```
    /**
     * @test
     */
    public function should_fail_validation_since_twitter_missing()
    {
        //Make a form request
        //Set validation on that related to twitter field
        //make sure the feature flag is on

        $user_id = Rhumsaa\Uuid\Uuid::uuid4()->toString();

        $user = factory(\App\User::class)->create([
            'id' => $user_id,
            'is_admin' => 1
        ]);

        $this->actingAs($user);

        factory(\FriendsOfCat\LaravelFeatureFlags\FeatureFlag::class)->create(
            [
                'key' => 'add-twitter-field',
                'variants' => 'on'
            ]
        );

        $this->registerFeatureFlags();
        ////
    }
```

TODO
----

[](#todo)

- Use Model Events to do that level of work
- Cache of the FeatureFlag Settings and update Cache on Change
- Show how it works in the menu and other areas eg include and Provider

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~91 days

Recently: every ~79 days

Total

28

Last Release

1202d ago

Major Versions

v1.0.0 → v2.0.22018-01-26

v1.0.1 → v2.0.02018-03-05

v2.1.0 → v3.0.02018-06-28

3.2.0 → v4.0.02021-07-21

PHP version history (4 changes)v1.0.0PHP &gt;=5.5.0

v2.0.0PHP ~5.6|~7.0

v3.0.0PHP ^7.1.3

v4.0.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/57e405b52d482c9de35b17f299d2745e8e68d9d9951aec64854f2d7fa53110bf?d=identicon)[luisdalmolin](/maintainers/luisdalmolin)

![](https://www.gravatar.com/avatar/da51f2fb140a4e118e94dd59ff819c11dd9a656b9c0ff8b2074c5fd2c07978ee?d=identicon)[alnutile](/maintainers/alnutile)

![](https://www.gravatar.com/avatar/deaa94d07a8cca75da55dcce1ed56e59d90dae65f06d2f74403a76394e24952f?d=identicon)[therobfonz](/maintainers/therobfonz)

![](https://www.gravatar.com/avatar/897a20ecccb931110423981826453afcc1ad0eb148ead352e2e705679821121b?d=identicon)[damiankloip](/maintainers/damiankloip)

![](https://www.gravatar.com/avatar/5f4ecb02d128ce6a62f06db86693fc6224accc7dccf8a30fec1ebf490a6457b5?d=identicon)[luiz.albertoni](/maintainers/luiz.albertoni)

---

Top Contributors

[![luiz-albertoni](https://avatars.githubusercontent.com/u/14180436?v=4)](https://github.com/luiz-albertoni "luiz-albertoni (19 commits)")[![therobfonz](https://avatars.githubusercontent.com/u/35386780?v=4)](https://github.com/therobfonz "therobfonz (15 commits)")[![alnutile](https://avatars.githubusercontent.com/u/365385?v=4)](https://github.com/alnutile "alnutile (14 commits)")[![damiankloip](https://avatars.githubusercontent.com/u/1053891?v=4)](https://github.com/damiankloip "damiankloip (7 commits)")[![luisdalmolin](https://avatars.githubusercontent.com/u/403446?v=4)](https://github.com/luisdalmolin "luisdalmolin (7 commits)")[![cvyz](https://avatars.githubusercontent.com/u/5907882?v=4)](https://github.com/cvyz "cvyz (3 commits)")[![andreeastrattner](https://avatars.githubusercontent.com/u/8161141?v=4)](https://github.com/andreeastrattner "andreeastrattner (1 commits)")

---

Tags

feature-flagsfeature-togglestoggles

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[ylsideas/feature-flags

A Laravel package for handling feature flags

6201.4M3](/packages/ylsideas-feature-flags)[flagception/flagception-bundle

Feature toggle bundle on steroids.

283.8M](/packages/flagception-flagception-bundle)[worksome/feature-flags

A package to manage feature flags in your application

11506.3k](/packages/worksome-feature-flags)

PHPackages © 2026

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