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

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

philiprehberger/laravel-feature-flags
=====================================

Lightweight feature flags with config and database drivers, percentage rollout, and scheduling

v1.1.1(3mo ago)142MITPHPPHP ^8.2CI passing

Since Mar 9Pushed 1mo agoCompare

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

READMEChangelogDependencies (17)Versions (10)Used By (0)

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

[](#laravel-feature-flags)

[![Tests](https://github.com/philiprehberger/laravel-feature-flags/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/laravel-feature-flags/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/b3a3b069b63e208e2e45ed26073871927bed39023d1962a4347f938793fe8b20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f6c61726176656c2d666561747572652d666c6167732e737667)](https://packagist.org/packages/philiprehberger/laravel-feature-flags)[![Last updated](https://camo.githubusercontent.com/901da2081aeabaf56b3588515f387cb94dc749eb0a8eefed651636b3fd383900/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f6c61726176656c2d666561747572652d666c616773)](https://github.com/philiprehberger/laravel-feature-flags/commits/main)

Lightweight feature flags with config and database drivers, percentage rollout, and scheduling.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

Install via Composer:

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

The service provider and `Feature` facade are registered automatically via Laravel's package auto-discovery.

### Publish the config

[](#publish-the-config)

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

### Publish and run the migration (database driver only)

[](#publish-and-run-the-migration-database-driver-only)

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

### Configuration

[](#configuration)

`config/feature-flags.php`:

```
return [

    // 'config' reads flags from the 'features' array below.
    // 'database' reads flags from the feature_flags table.
    'driver' => env('FEATURE_FLAGS_DRIVER', 'config'),

    'features' => [
        // Simple on/off flag
        'new-checkout' => true,

        // Partial rollout — 25% of users will see this feature
        'beta-dashboard' => ['active' => true, 'rollout' => 25],

        // Scheduled flag — only active between the two dates
        'holiday-banner' => [
            'active'        => true,
            'enabled_from'  => '2026-12-01',
            'enabled_until' => '2026-12-31',
        ],

        // Combined: rollout + scheduling
        'early-access' => [
            'active'       => true,
            'rollout'      => 10,
            'enabled_from' => '2026-06-01',
        ],
    ],

];
```

Set the driver via your `.env`:

```
FEATURE_FLAGS_DRIVER=database
```

Usage
-----

[](#usage)

### Facade

[](#facade)

```
use PhilipRehberger\FeatureFlags\Facades\Feature;

// Global check (no user context)
if (Feature::active('new-checkout')) {
    // ...
}

// Per-user check (respects rollout percentage)
if (Feature::for($request->user())->active('beta-dashboard')) {
    // ...
}

// List all defined flags
$flags = Feature::allFeatures();

// Enable / disable at runtime (database driver only)
Feature::enable('new-checkout');
Feature::disable('new-checkout');
```

### Custom Rules

[](#custom-rules)

Register a callable that must also pass for a feature to be active. Rules are evaluated after percentage rollout and scheduling. The callable receives the user (or `null` for global checks) and must return a bool:

```
use PhilipRehberger\FeatureFlags\Facades\Feature;

// Only allow users with a verified email
Feature::rule('beta-dashboard', function (?Authenticatable $user): bool {
    return $user !== null && $user->hasVerifiedEmail();
});

// Rules combine with rollout — both must pass
// Here only verified users within the 25% rollout see the feature
Feature::for($request->user())->active('beta-dashboard');

// Global check passes null to the rule
Feature::active('beta-dashboard'); // rule receives null
```

### Blade Directives

[](#blade-directives)

Global check:

```
@feature('new-checkout')

@endfeature
```

With an else branch (plain PHP `@else`):

```
@feature('new-checkout')

@else

@endfeature
```

Conditional on a second feature (`@elsefeature` is the elseif variant):

```
@feature('checkout-v3')

@elsefeature('new-checkout')

@endfeature
```

Per-user check (respects rollout):

```
@featurefor('beta-dashboard', auth()->user())

@endfeaturefor
```

### Route Middleware

[](#route-middleware)

Protect a route so it returns 403 when the feature is inactive:

```
Route::get('/checkout/v2', CheckoutV2Controller::class)
    ->middleware('feature:new-checkout');
```

When the request has an authenticated user, the per-user rollout check is applied. Otherwise the global active state is used.

### Artisan Commands

[](#artisan-commands)

```
# List all feature flags with status, rollout, and schedule
php artisan feature:list

# Enable a flag (database driver only)
php artisan feature:enable new-checkout

# Disable a flag (database driver only)
php artisan feature:disable new-checkout
```

Example `feature:list` output:

```
+------------------+---------+------------+-----------+-------------+
| Name             | Status  | Rollout    | Schedule  | Description |
+------------------+---------+------------+-----------+-------------+
| new-checkout     | active  | all users  | always    | —           |
| beta-dashboard   | active  | 25%        | always    | —           |
| holiday-banner   | active  | all users  | 2026-12-01 → 2026-12-31 | — |
+------------------+---------+------------+-----------+-------------+

```

### Drivers

[](#drivers)

#### Config Driver

[](#config-driver)

Flags are defined in `config/feature-flags.php`. Changes require a deployment. This is the default driver and ideal for flags that are tied to your release cycle.

#### Database Driver

[](#database-driver)

Flags are stored in the `feature_flags` table and can be toggled at runtime via Artisan commands, the facade, or any database tooling. Run the migration before using this driver.

The migration creates the following columns:

ColumnTypeDescription`id`bigintPrimary key`name`string (unique)Flag identifier`description`string (nullable)Optional description`active`booleanMaster on/off switch`rollout_percentage`tinyint (nullable)Percentage of users (0–100)`enabled_from`timestamp (nullable)Activation start`enabled_until`timestamp (nullable)Activation end`created_at` / `updated_at`timestampsStandard Laravel timestamps### Rollout Logic

[](#rollout-logic)

Percentage rollout uses a deterministic hash to ensure the same user always receives the same result:

```
$hash = abs(crc32($featureName . $user->getAuthIdentifier()));
$active = ($hash % 100) < $rolloutPercentage;
```

A user in the 25% bucket for `beta-dashboard` will always be in that bucket — they will not flip between requests, and adding new flags will not affect their bucket for existing flags.

### Scheduling

[](#scheduling)

When `enabled_from` or `enabled_until` are set, the flag is only active during the configured window. Dates are parsed with Carbon, so any format Carbon accepts is valid (e.g. `'2026-12-01'`, `'2026-12-01 09:00:00'`).

API
---

[](#api)

### `Feature` Facade

[](#feature-facade)

MethodDescription`Feature::rule(string $name, callable $rule): void`Register a custom rule for a feature`Feature::active(string $name): bool`Check if a feature is active (global check)`Feature::for(Authenticatable $user): static`Set a user context for rollout checks`Feature::allFeatures(): array`Return all defined feature flags`Feature::enable(string $name): void`Enable a flag at runtime (database driver only)`Feature::disable(string $name): void`Disable a flag at runtime (database driver only)### Blade Directives

[](#blade-directives-1)

DirectiveDescription`@feature('name') ... @endfeature`Render block when feature is active`@feature('name') ... @else ... @endfeature`Render alternate block when feature is inactive`@elsefeature('name') ... @endfeature`Else-if variant for a second feature check`@featurefor('name', $user) ... @endfeaturefor`Per-user feature check respecting rolloutDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/laravel-feature-flags)

🐛 [Report issues](https://github.com/philiprehberger/laravel-feature-flags/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/laravel-feature-flags/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance87

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~1 days

Total

9

Last Release

96d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelrolloutfeature-flagsfeature-togglesab-testing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M153](/packages/spatie-laravel-health)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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