PHPackages                             offload-project/laravel-toggle - 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. offload-project/laravel-toggle

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

offload-project/laravel-toggle
==============================

A simple and flexible feature toggle (feature flag) package for Laravel

v1.2.1(4mo ago)0368↓50%MITPHPPHP ^8.2CI passing

Since Jan 14Pushed 4mo agoCompare

[ Source](https://github.com/offload-project/laravel-toggle)[ Packagist](https://packagist.org/packages/offload-project/laravel-toggle)[ Docs](https://github.com/offload-project/laravel-toggle)[ RSS](/packages/offload-project-laravel-toggle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (11)Versions (5)Used By (0)

 [![Latest Version on Packagist](https://camo.githubusercontent.com/55dd59d155ce974390a7ed59ff73627d39ee393f48f64881642387a21ce640cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/offload-project/laravel-toggle) [![GitHub Tests Action Status](https://camo.githubusercontent.com/e3eb8c6456795bc5856975de41845f8e127848163b127453e5a5dd8fd09e14aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/offload-project/laravel-toggle/actions) [![Total Downloads](https://camo.githubusercontent.com/f968f9455ef22a73b9e6b3608b73cd170e54064896555a064f1d7b4f2e813580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/offload-project/laravel-toggle)

Laravel Toggle
==============

[](#laravel-toggle)

A simple and flexible feature toggle (feature flag) package for Laravel. Control feature rollouts with config-based flags, database-driven toggles, or both.

Features
--------

[](#features)

- **Two storage drivers**: Config (environment variables) or Database (runtime toggleable)
- **Layered approach**: Database driver falls back to config, allowing gradual migration
- **Built-in caching**: Configurable cache store and TTL for performance
- **Blade directives**: `@toggle`, `@elsetoggle`, `@endtoggle` for clean templates
- **Enum support**: Use backed enums for type-safe toggle names
- **Artisan commands**: Scaffold new toggles and manage cache
- **Configurable defaults**: Return false, true, or throw exceptions for undefined toggles

Why Laravel Toggle?
-------------------

[](#why-laravel-toggle)

Laravel's first-party [Pennant](https://github.com/laravel/pennant) package is designed for user-segmented rollouts and A/B testing. Laravel Toggle is simpler — it's for global on/off switches controlled by environment variables or database records, with no user resolution or driver complexity.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require offload-project/laravel-toggle
```

Publish the configuration file:

```
php artisan vendor:publish --tag=toggle-config
```

If using the database driver, publish and run the migrations:

```
php artisan vendor:publish --tag=toggle-migrations
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

### Define a toggle in config

[](#define-a-toggle-in-config)

Add your feature flags to `config/toggle.php`:

```
'flags' => [
    'new-checkout' => env('TOGGLE_NEW_CHECKOUT', false),
    'dark-mode' => env('TOGGLE_DARK_MODE', true),
],
```

### Check toggles in code

[](#check-toggles-in-code)

```
use OffloadProject\Toggle\Facades\Toggle;

if (Toggle::active('new-checkout')) {
    // New checkout flow
}

if (Toggle::inactive('dark-mode')) {
    // Light mode only
}
```

### Use Blade directives

[](#use-blade-directives)

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

@elsetoggle

@endtoggle
```

Configuration
-------------

[](#configuration)

### Driver

[](#driver)

Set the driver in your `.env` file:

```
TOGGLE_DRIVER=config   # Read-only, uses config/toggle.php flags
TOGGLE_DRIVER=database # Read-write, falls back to config
```

The **config driver** is read-only at runtime - values come from environment variables and config files.

The **database driver** checks the database first, then falls back to config values. This allows you to define defaults in config while overriding specific toggles at runtime.

### Default behavior for undefined toggles

[](#default-behavior-for-undefined-toggles)

```
TOGGLE_DEFAULT=false     # Return false (default)
TOGGLE_DEFAULT=true      # Return true
TOGGLE_DEFAULT=exception # Throw ToggleNotFoundException
```

### Caching

[](#caching)

```
TOGGLE_CACHE_ENABLED=true
TOGGLE_CACHE_STORE=redis  # null uses default cache store
TOGGLE_CACHE_TTL=3600     # seconds
```

Usage
-----

[](#usage)

### Facade methods

[](#facade-methods)

```
use OffloadProject\Toggle\Facades\Toggle;

// Check if active
Toggle::active('feature-name');    // bool
Toggle::inactive('feature-name');  // bool

// Modify toggles (database driver only)
Toggle::enable('feature-name');   // Enable a toggle
Toggle::disable('feature-name');  // Disable a toggle
Toggle::delete('feature-name');     // Remove from database

// Get all toggles
Toggle::all(); // ['feature-name' => true, ...]

// Cache management
Toggle::forgetCache('feature-name'); // Clear specific toggle
Toggle::flushCache();                // Clear all toggles
```

### Using enums

[](#using-enums)

Define your toggles as a backed enum for type safety:

```
enum Feature: string
{
    case NewCheckout = 'new-checkout';
    case DarkMode = 'dark-mode';
    case BetaFeatures = 'beta-features';
}
```

Use the enum directly:

```
use App\Enums\Feature;

if (Toggle::active(Feature::NewCheckout)) {
    // ...
}

Toggle::enable(Feature::BetaFeatures);
```

### Eloquent model

[](#eloquent-model)

When using the database driver, you can also use the `Toggle` model directly:

```
use OffloadProject\Toggle\Models\Toggle;

// Query toggles
$toggle = Toggle::where('name', 'new-checkout')->first();

// Create or update
Toggle::updateOrCreate(
    ['name' => 'new-checkout'],
    ['active' => true]
);
```

The model automatically clears the cache when toggles are saved or deleted.

### Inertia

[](#inertia)

Share all toggles with your frontend by using the provided Inertia middleware. Replace your `HandleInertiaRequests` middleware in `bootstrap/app.php`:

```
use OffloadProject\Toggle\Middleware\ShareTogglesWithInertia;

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        ShareTogglesWithInertia::class,
    ]);
})
```

All toggles will be available as the `flags` prop in your frontend:

```
// Vue/React
const { flags } = usePage().props

if (flags.newCheckout) {
    // Show new checkout
}
```

Artisan Commands
----------------

[](#artisan-commands)

### List all toggles

[](#list-all-toggles)

```
php artisan toggle:list
```

Displays a table of all defined toggles and their current state.

### Create a toggle

[](#create-a-toggle)

```
# Create a config-based toggle
php artisan toggle:create new-feature

# Create as active by default
php artisan toggle:create new-feature --active

# Also create a database record
php artisan toggle:create new-feature --active --db
```

This command will:

- Add the flag to `config/toggle.php`
- Add the environment variable to `.env`
- Optionally create a database record

### Clear cache

[](#clear-cache)

```
# Clear all toggle caches
php artisan toggle:cache-clear

# Clear a specific toggle
php artisan toggle:cache-clear new-feature
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance77

Regular maintenance activity

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% 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 ~0 days

Total

4

Last Release

124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/331bcc01f75f46dded875d74f3db055da6d74be5f8820f0a29105c6a2cd8afc8?d=identicon)[shavonn](/maintainers/shavonn)

---

Top Contributors

[![shavonn](https://avatars.githubusercontent.com/u/3074595?v=4)](https://github.com/shavonn "shavonn (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

laravelflagsfeature-flagsfeature-togglestoggles

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/offload-project-laravel-toggle/health.svg)

```
[![Health](https://phpackages.com/badges/offload-project-laravel-toggle/health.svg)](https://phpackages.com/packages/offload-project-laravel-toggle)
```

###  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)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laravel/pennant

A simple, lightweight library for managing feature flags.

57711.1M53](/packages/laravel-pennant)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[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)
