Feature Flags with Pennant

A feature flag lets you ship code switched off, enable it for staff, then for 10% of customers, and disable it again without a deploy. Pennant 1.26.0 is Laravel 2,157 's first-party flag library. After composer require laravel/pennant, publish and run its migration to create a features table:

app/Providers/AppServiceProvider.php: one flag, two audiencesPHP
public function boot(): void
{
    Feature::define('new-checkout', fn (User $user) => match (true) {
        str_ends_with($user->email, '@example.com') => true,  // staff first
        default => Lottery::odds(1, 10),                     // then 10% of customers
    });
}

A Tinker script checked Feature::for($user)->active('new-checkout') for one staff account and 200 factory customers, then called deactivate() for the staff account:

Output of 209
staff: true
customers with the feature: 16 of 200
stored rows: 201
staff after deactivate: false

The lottery ran once per user and was stored as a row (new-checkout | App\Models\User|2 | false), so each customer gets a stable answer. Check a flag with Feature::active('new-checkout'), the @feature Blade directive or the EnsureFeaturesAreActive middleware. Remove a finished flag with Feature::purge(), and turn one on in tests with Feature::activate().