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

v2.1.0(2w ago)251.6k↓11.1%1MITPHPPHP ^8.2CI passing

Since Jan 14Pushed 2w ago1 watchersCompare

[ 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 3d ago

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

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

[](#laravel-toggle)

[![Latest Version on Packagist](https://camo.githubusercontent.com/55dd59d155ce974390a7ed59ff73627d39ee393f48f64881642387a21ce640cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/offload-project/laravel-toggle)[![Tests](https://camo.githubusercontent.com/dc95cd52a7d532f7d1a5607a5be1b7ab87e3bf8c4e42b6ff0069d5e95379f1b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/offload-project/laravel-toggle/actions/workflows/tests.yml)[![Build](https://camo.githubusercontent.com/ba03d3fda2155e03b357c7378510282524936c4fc85678e15f52d538b2079a1d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652f72656c656173652e796d6c3f6c6162656c3d6275696c64267374796c653d666c61742d737175617265)](https://github.com/offload-project/laravel-toggle/actions/workflows/release.yml)[![Total Downloads](https://camo.githubusercontent.com/f968f9455ef22a73b9e6b3608b73cd170e54064896555a064f1d7b4f2e813580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f66666c6f61642d70726f6a6563742f6c61726176656c2d746f67676c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/offload-project/laravel-toggle)[![License: MIT](https://camo.githubusercontent.com/6c711032aff1ca0eb6b211aa6cb3649ce7fd64a7714e1181d4bb457f9680e7cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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)
- **Per-flag driver routing** - Mix config and database flags in the same app via `database_flags`
- **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
- **Inertia integration** - Share all flags with the frontend via middleware
- **Configurable defaults** - Return false, true, or throw exceptions for undefined toggles

Table of Contents
-----------------

[](#table-of-contents)

- [Why Laravel Toggle?](#why-laravel-toggle)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
    - [Define a toggle in config](#define-a-toggle-in-config)
    - [Check toggles in code](#check-toggles-in-code)
    - [Use Blade directives](#use-blade-directives)
- [Configuration](#configuration)
    - [Driver](#driver)
    - [Per-flag driver routing](#per-flag-driver-routing)
    - [Default behavior for undefined toggles](#default-behavior-for-undefined-toggles)
    - [Caching](#caching)
- [Usage](#usage)
    - [Facade methods](#facade-methods)
    - [Using enums](#using-enums)
    - [Eloquent model](#eloquent-model)
    - [Inertia](#inertia)
- [Artisan Commands](#artisan-commands)
- [AI Coding Assistant Skill](#ai-coding-assistant-skill)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

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.3+
- Laravel 11/12/13

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

[](#installation)

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

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.

### Per-flag driver routing

[](#per-flag-driver-routing)

You can mix both drivers in the same application. Define config-driven flags in `flags` and list database-driven flags in `database_flags`:

```
// config/toggle.php

'flags' => [
    // Config-driven, read-only — controlled by .env
    'new-checkout' => env('TOGGLE_NEW_CHECKOUT', false),
    'dark-mode' => env('TOGGLE_DARK_MODE', true),
],

'database_flags' => [
    // Database-driven, mutable at runtime via Toggle::enable() / Toggle::disable()
    'maintenance-banner',
    'beta-access',
],
```

Resolution logic:

- Flags in `database_flags` always use the database driver (with config fallback)
- Flags in `flags` always use the config driver (read-only)
- Unlisted flags use the global `driver` setting

This lets you keep stable flags in `.env` while allowing runtime control over flags that need to change without a deploy.

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

AI Coding Assistant Skill
-------------------------

[](#ai-coding-assistant-skill)

This package ships a [Laravel Boost](https://skills.laravel.cloud/) skill so coding assistants (Claude Code, Cursor, etc.) follow the package's conventions when generating code. Install it in your app with:

```
php artisan boost:add-skill offload-project/laravel-toggle
```

The skill source lives at [`skills/SKILL.md`](skills/SKILL.md).

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Contributions are welcome! Please see the documents below before getting started.

- [Contributing Guide](CONTRIBUTING.md) — setup, workflow, commit conventions, and PR process
- [Code of Conduct](CODE_OF_CONDUCT.md) — expectations for participation in this project

Security
--------

[](#security)

- [Security Policy](SECURITY.md) — how to report a vulnerability privately

License
-------

[](#license)

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

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance96

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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 ~25 days

Recently: every ~38 days

Total

7

Last Release

20d ago

Major Versions

v1.3.0 → v2.0.02026-04-27

### 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 (21 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 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

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M201](/packages/laravel-ai)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[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)
