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

AbandonedArchivedLibrary

dive-be/laravel-feature-flags
=============================

Handle feature flags within your Laravel app

1.1(4y ago)22.4kMITPHPPHP ^8.1

Since Feb 28Pushed 3y agoCompare

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

READMEChangelog (5)Dependencies (16)Versions (6)Used By (0)

⛳️ - Abandoned
==============

[](#️---abandoned)

Please use much better alternatives:

- [ryangjchandler/laravel-feature-flags](https://github.com/ryangjchandler/laravel-feature-flags)
- [juststeveking/laravel-feature-flags](https://github.com/JustSteveKing/laravel-feature-flags)
- [ylsideas/feature-flags](https://github.com/ylsideas/feature-flags)

What problem does this package solve?
-------------------------------------

[](#what-problem-does-this-package-solve)

"A feature flag is a software development process used to enable or disable functionality remotely without deploying code. New features can be deployed without making them visible to users. Feature flags help decouple deployment from release letting you manage the full lifecycle of a feature." ([Source](https://launchdarkly.com/blog/what-are-feature-flags))

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

[](#installation)

You can install the package via composer:

```
composer require dive-be/laravel-feature-flags
```

Once composer has finished, you must publish the configuration and migration:

```
php artisan feature:install
```

This is the contents of the published config file:

```
return [

    /**
     * The name of the cache key that will be used to cache your app's features.
     */
    'cache_key' => 'feature_flags',

    /**
     * The feature model that will be used to retrieve your app's features.
     */
    'feature_model' => Dive\FeatureFlags\Models\Feature::class,
];
```

If you don't need multi-locale support, you are now good to go.

### Multiple languages support

[](#multiple-languages-support)

This package provides first-class support for multiple languages using Spatie's excellent [Laravel translatable package](https://github.com/spatie/laravel-translatable).

```
composer require spatie/laravel-translatable
```

Next, go to the configuration file and change `feature_model` to:

```
Dive\FeatureFlags\Models\TranslatableFeature::class
```

Finally, find the migration and uncomment the comment while also deleting everything in front of it. It should read:

```
// ...
$table->json('message')->nullable();
$table->timestamp('disabled_at')->nullable();
// ...
```

Usage
-----

[](#usage)

For a full list of what's available to you, please refer to the *[Feature contract](https://github.com/dive-be/laravel-feature-flags/blob/master/src/Contracts/Feature.php)* for an exhaustive list.

### Setting up your app's initial features

[](#setting-up-your-apps-initial-features)

Seeding the (initial) features can be done in a regular Laravel seeder.

```
php artisan make:seeder FeaturesTableSeeder
```

Here is an example of what it might look like:

```
use Dive\FeatureFlags\Models\Feature;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class FeaturesTableSeeder extends Seeder
{
    public function run()
    {
        DB::table('features')->upsert([
            [
                'description' => 'Registrations that come through our partnerships',
                'label' => 'Public registrations',
                'message' => 'The registration period has ended. Thanks for participating in our programme.',
                'name' => 'registrations',
                'scope' => Feature::getDefaultScope(),
            ],
            [
                'description' => 'Display the App version on the homepage',
                'label' => 'Application version',
                'message' => 'Version is hidden',
                'name' => 'version',
                'scope' => Feature::getDefaultScope(),
            ],
        ], ['scope', 'name'], ['description', 'label', 'message']);
    }
}
```

### Resolving the manager

[](#resolving-the-manager)

This package provides every possible way to resolve a `Feature` instance out of the IoC container. We've got you covered!

#### Facade

[](#facade)

```
use Dive\FeatureFlags\Facades\Feature;

Feature::find('dashboard');
```

or using the alias (particularly helpful in Blade views)

```
use Feature;

Feature::disabled('dashboard');
```

#### Helpers

[](#helpers)

```
feature('dashboard');
feature_disabled('dashboard');
feature_enabled('dashboard');
feature_verify('dashboard');
```

#### Dependency injection

[](#dependency-injection)

```
use Dive\FeatureFlags\Contracts\Feature;

public function index(Feature $feature)
{
    $feature->verify('dashboard');

    return view('layouts.dashboard');
}
```

#### Service Location

[](#service-location)

```
app('feature')->find('dashboard');
```

Scoping
-------

[](#scoping)

The package allows you to define a custom scope along with the feature (not to be confused with Laravel's global scopes). Particularly useful when you need to use the same name for different parts of your application. Most of the package's functions/methods accept an additional `$scope` argument.

Refer to the [Feature contract](https://github.com/dive-be/laravel-feature-flags/blob/master/src/Contracts/Feature.php) for an exhaustive list.

### Changing the default wildcard scope

[](#changing-the-default-wildcard-scope)

If you wish to use a different scope rather than the `*` sign the package uses by default when creating and checking/verifying features, you may change this in your `AppServiceProvider`'s `boot` method:

```
use Dive\FeatureFlags\Models\Feature;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Feature::setDefaultScope('my-wonderful-app');
    }
}
```

### Seeding

[](#seeding)

Refer to the [seeding section](#setting-up-your-apps-initial-features) above on how to scope your features.

Blade directives 🗡
------------------

[](#blade-directives-)

### @disabled

[](#disabled)

You can use the `@disabled` directive to conditionally display content in your views depending on a feature's current state. Using this directive first will make the feature's `message` property automatically available as a scoped variable inside the block. Examples:

```
@disabled('registrations')

        {{ $message }}

@enabled

        Welcome to our public registrations.

@enddisabled
```

### @enabled

[](#enabled)

You can also use the `@enabled` directive to do the same thing as above. However, the `$message` variable will **not** be available inside the `@disabled` block when using this directive **first**.

```
@enabled('registrations')
    text
@disabled
    $message is not available here
@endenabled
```

### @can(not)

[](#cannot)

This package also registers itself at [Laravel's Gate](https://laravel.com/docs/8.x/authorization#gates). The visitor does not have to be auhenticated in order to use it:

```
@can('feature', 'dashboard')
    View Dashboard
@else
    Dashboard is currently disabled
@endcan
```

Guarding parts of your application 💂🏼
-------------------------------------

[](#guarding-parts-of-your-application-)

There are multiple ways to prevent users from accessing disabled parts of your application.

A `FeatureDisabledException` will be thrown in all cases if the feature is not enabled.

### Route middleware

[](#route-middleware)

```
Route::get('registrations', [RegistrationsController::class, 'index'])->middleware('feature:registrations');
```

### Manual checking using 'verify'

[](#manual-checking-using-verify)

#### Controller example

[](#controller-example)

Assume your typical controller:

```
class RegistrationsController extends Controller
{
    public function __construct(Feature $feature)
    {
        $feature->verify('registrations');
    }

    public function index()
    {
        return view('registrations.index');
    }
}
```

#### Livewire example

[](#livewire-example)

This is especially useful in contexts where you cannot really use route middleware, such as [Livewire actions](https://laravel-livewire.com/docs/2.x/actions):

```
use Dive\FeatureFlags\Facades\Feature;
use Dive\Wishlist\Facades\Wishlist;

class HeartButton extends Component
{
    public function add($id)
    {
        Feature::verify('wishlist');

        Wishlist::add($id);
    }

    public function render()
    {
        return view('livewire.heart-button');
    }
}
```

> PS: Be sure to check out our [Wishlist package](https://github.com/dive-be/laravel-wishlist) as well 😉

### Access Gate

[](#access-gate)

This package also registers itself at [Laravel's Gate](https://laravel.com/docs/8.x/authorization#gates) providing you the ability to check a feature's state through them. This means that you can do things like the following:

```
Route::get(...)->middleware('can:feature,dashboard');
```

```
Gate::authorize('feature', 'dashboard');
```

**However**, there is one key difference. Laravel's Gate will throw an `AccessDeniedHttpException`, while the package's own checks will throw a `FeatureDisabledException` (which extends the former exception class). So, if you need to know the exception's type, you are highly adviced **not** to use gates.

Artisan commands 🧑‍🎨
--------------------

[](#artisan-commands-‍)

### Toggling a feature on/off

[](#toggling-a-feature-onoff)

Since the features are managed through a `Feature` Eloquent model, you can definitely use solutions such as Laravel Nova to do this.

However, when developing locally, you might want to easily turn a feature on/off. You can do this using the command below:

```
php artisan feature:toggle {name} {scope?}

```

### Displaying list of all features

[](#displaying-list-of-all-features)

Use the command below to display a table of all features and their corresponding state:

```
php artisan feature:list
```

Available options: `compact`, `disabled`, `enabled`, `scope`.

### Clearing the cache

[](#clearing-the-cache)

The features are cached forever to speed up subsequent checks. If you don't use Eloquent to update or alter records, you must reset the cache manually:

```
php artisan feature:clear
```

> Note: when you create/update features through Eloquent, the cache busting is done for you automatically.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Muhammed Sari](https://github.com/mabdullahsari)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Total

5

Last Release

1549d ago

Major Versions

0.2 → 1.02021-09-11

PHP version history (3 changes)0.1PHP &gt;=8.0

1.0PHP ^8.0

1.1PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![mabdullahsari](https://avatars.githubusercontent.com/u/24608797?v=4)](https://github.com/mabdullahsari "mabdullahsari (1 commits)")

---

Tags

laravelflagsfeaturefeature-flagsdive

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[aedart/athenaeum

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

255.2k](/packages/aedart-athenaeum)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M531](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)

PHPackages © 2026

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