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

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

filipefernandes/laravel-feature-flags
=====================================

Reusable Laravel feature flag system

0.0.9(8mo ago)5377MITPHPPHP ^8.1

Since Jul 16Pushed 8mo agoCompare

[ Source](https://github.com/filipefernandes9747/laravel-feature-flags)[ Packagist](https://packagist.org/packages/filipefernandes/laravel-feature-flags)[ RSS](/packages/filipefernandes-laravel-feature-flags/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (10)Used By (0)

🔀 Laravel Feature Flags
=======================

[](#-laravel-feature-flags)

A robust, extensible, and testable **feature flag system** for Laravel 10+ with Vue/SPA frontend support. Designed as a reusable package for modern Laravel apps.

✨ Features
----------

[](#-features)

- ✅ Configurable flags (in config file or database)
- ✅ Boolean or closure-based evaluation
- ✅ Environment-specific overrides
- ✅ Persisted flags in DB (with optional validation)
- ✅ Blade directive: `@feature('flag')`
- ✅ Livewire &amp; Inertia integration
- ✅ Middleware for routes or groups
- ✅ Artisan commands to list and manage flags
- ✅ Ui for managing feature flags and history
- ✅ Built with testability &amp; reusability in mind

---

📦 Installation
--------------

[](#-installation)

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

### 1. Publish config and migration

[](#1-publish-config-and-migration)

```
php artisan feature-flag:install {--force: if you want to replace the current files}
```

---

⚙️ Configuration
----------------

[](#️-configuration)

The main config lives in:

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

Example:

```
return [
    'flags' => [
        'flag_1' => [
            'enabled' => true,
            'closure' => fn () => auth()->check() && auth()->user()->is_beta,
        ],
        'flag_2' => [
            'enabled' => [
                'dev' => true,
                'prod' => false
            ],
        ],
        'flag_3' => [
            'enabled' => [
                'dev' => fn () => auth()->check() && auth()->user()->is_beta,
                'prod' => true
            ],
        ],
    ],

    'ui' => [
        'enabled' => true,
        'middleware' => [],
        'route_prefix' => 'admin/flags',
        'options' => [
            'beta testers' => fn ($context) => $context->is_beta_testers,
            'admin' => fn (User $user) => $user->is_admin,
            ...
        ]
    ],
];
```

You can define static booleans or closures. If the flag is enabled in DB and has a closure, it will be resolved dynamically or can use the ui for defining the conditionals.

---

🧪 Usage
-------

[](#-usage)

### ✅ Check if a flag is enabled

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

```
use FeatureFlags;

// Simple check if a feature flag is enabled for the current user and environment
if (FeatureFlags::isEnabled('new_dashboard')) {
    // Show the new dashboard
}
```

---

### 🔄 Check if a flag is enabled with a custom context and environment

[](#-check-if-a-flag-is-enabled-with-a-custom-context-and-environment)

```
$user = User::find(123);
$environment = 'staging';

if (FeatureFlags::isEnabled(key: 'beta_feature',context: $user, environment: $environment)) {
    // Enable beta feature for this user in staging environment
}
```

---

### ⚙️ Check a flag with a custom callback

[](#️-check-a-flag-with-a-custom-callback)

```
FeatureFlags::isEnabled(key:'complex_feature', closure: function ($user) {
    return $user->isAdmin() && $user->created_at->diffInDays(now()) > 30;
});
```

---

### 📋 Check multiple flags

[](#-check-multiple-flags)

```
// Check if all flags are enabled
$allEnabled = FeatureFlags::allAreEnabled(['feature_a', 'feature_b']);

// Check if some flags are enabled
$someEnabled = FeatureFlags::someAreEnabled(['feature_c', 'feature_d']);
```

---

### 📋 Get all active (enabled) feature flags

[](#-get-all-active-enabled-feature-flags)

Retrieve an array of all currently enabled feature flags, considering both the database and config settings.

```
use FeatureFlags;

// Get all active flags for the current environment (default)
$activeFlags = FeatureFlags::all();

// Get all active flags for a specific environment (e.g., 'staging', 'production')
$activeFlagsInStaging = FeatureFlags::all('staging');
```

---

### ⚙️ Behavior notes

[](#️-behavior-notes)

- By default, the method uses the current app environment (`app()->environment()`).
- If your `feature-flags.environments` config is defined and non-empty, the method respects environment-specific overrides on each flag.
- If the global environments config is empty or missing, environment checks are ignored, and only the flag’s `enabled` status is used.
- Flags defined in the database override config flags.
- The result is cached for the time setting the config file for performance.

---

### 🔄 Clear cache

[](#-clear-cache)

```
FeatureFlags::clearCache();
```

### ✅ Blade directive

[](#-blade-directive)

```
@feature('new_dashboard')

@else

@endfeature
```

### ✅ Inertia support

[](#-inertia-support)

`featureFlags` are automatically shared with frontend (if configured):

```
import { usePage } from "@inertiajs/vue3";

const featureFlags = usePage().props.featureFlags;
```

### ✅ Livewire support

[](#-livewire-support)

Available in views and component logic:

```
if (FeatureFlags::isEnabled('experimental_widget')) {
    // ...
}
```

### ✅ Middleware

[](#-middleware)

Apply to a route or group:

```
Route::middleware(['feature:some_flag'])->get('/beta', fn () => 'Beta content');
```

---

🛠 CLI Commands
--------------

[](#-cli-commands)

### List all feature flags

[](#list-all-feature-flags)

```
php artisan feature:flags
```

### Enable/disable a flag

[](#enabledisable-a-flag)

```
php artisan feature:enable new_dashboard
php artisan feature:disable new_dashboard
```

✅ Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10+
- Optional: Livewire, Inertia

---

📜 License
---------

[](#-license)

MIT © [Filipe Fernandes](https://github.com/filipefernandes)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance60

Regular maintenance activity

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% 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 ~5 days

Total

9

Last Release

256d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/44c4a0ab684a6ff2f571c5b6b1db79320570f053120dadb2793c9b8ee41529a3?d=identicon)[filipe9747](/maintainers/filipe9747)

---

Top Contributors

[![ffernandes9747](https://avatars.githubusercontent.com/u/106343739?v=4)](https://github.com/ffernandes9747 "ffernandes9747 (19 commits)")[![filipefernandes9747](https://avatars.githubusercontent.com/u/22693486?v=4)](https://github.com/filipefernandes9747 "filipefernandes9747 (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  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)
