laravel-feature-flags
БесплатноБез исполняемых скриптовНе проверенBest practices for Laravel Pennant feature flags including defining features, checking activation, scoping, rich values for A/B testing, and gradual rollouts.
от iSerter★ 48 звёзд на GitHubОб этом скилле
Feature Flags with Laravel Pennant
Installing Pennant
composer require laravel/pennant
php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider"
php artisan migrate
Defining Features
Closure-Based Features
<?php
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Lottery;
use Laravel\Pennant\Feature;
public function boot(): void
{
// Simple boolean feature
Feature::define('new-dashboard', function () {
return true;
});
// Scoped to the authenticated user
Feature::define('beta-access', function (User $user) {
return $user->is_beta_tester;
});
// Gradual rollout with lottery
Feature::define('redesigned-checkout', function (User $user) {
return Lottery::odds(1, 10); // 10% of users
});
// Based on user attributes
Feature::define('premium-features', function (User $user) {
return $user->subscribed('premium');
});
}
Class-Based Features
php artisan pennant:feature NewOnboarding
<?php
namespace App\Features;
use App\Models\User;
use Illuminate\Support\Lottery;
class NewOnboarding
{
// Resolve the feature's initial value
public function resolve(User $user): mixed
{
return match (true) {
$user->isInternal() => true,
$user->created_at->isAfter('2025-01-01') => true,
default => Lottery::odds(1, 5),
};
}
}
// Usage with class-based features
Feature::active(NewOnboarding::class); // for the authenticated user
Feature::for($user)->active(NewOnboarding::class);
Checking Features
Basic Checks
use Laravel\Pennant\Feature;
// ✅ Check if active
if (Feature::active('new-dashboard')) {
// Show new dashboard
}
// ✅ Check if inactive
if (Feature::inactive('new-dashboard')) {
// Show old dashboard
}
// ✅ Check multiple features
if (Feature::allAreActive(['new-dashboard', 'beta-access'])) {
// All features are active
}
if (Feature::someAreActive(['feature-a', 'feature-b'])) {
// At least one is active
}
if (Feature::allAreInactive(['deprecated-feature', 'old-ui'])) {
// None of these are active
}
if (Feature::someAreInactive(['feature-a', 'feature-b'])) {
// At least one is inactive
}
Getting Values
// Get the resolved value (may not be boolean)
$value = Feature::value('purchase-button');
// Get values for multiple features
$values = Feature::values(['feature-a', 'feature-b']);
// ['feature-a' => true, 'feature-b' => 'variant-b']
Feature Scoping
User Scoping
// Check for the currently authenticated user (default)
Feature::active('beta-access');
// Check for a specific user
Feature::for($user)->active('beta-access');
// Check for multiple users
$users = User::where('role', 'admin')->get();
Feature::for($users)->active('beta-access');
Team / Custom Scoping
// Define a team-scoped feature
Feature::define('team-billing-v2', function (Team $team) {
return $team->plan === 'enterprise';
});
// Check for a specific team
Feature::for($team)->active('team-billing-v2');
Nullable Scope
// Define a feature with nullable scope (for guests)
Feature::define('maintenance-banner', function (User|null $user) {
return config('app.show_maintenance_banner');
});
// Check without authentication
Feature::for(null)->active('maintenance-banner');
Rich Values for A/B Testing
// Define a feature with rich values
Feature::define('purchase-button', function (User $user) {
return Lottery::odds(1, 3)->choose(
fn () => 'blue-button', // 33%
fn () => 'green-button', // 67% (default)
);
});
// Alternative: deterministic assignment
Feature::define('purchase-button', function (User $user) {
return match ($user->id % 3) {
0 => 'blue-button',
1 => 'green-button',
2 => 'red-button',
};
});
{{-- Using rich values in views --}}
@php $variant = Feature::value('purchase-button') @endphp
@if ($variant === 'blue-button')
<button class="bg-blue-600 text-white">Buy Now</button>
@elseif ($variant === 'green-button')
<button class="bg-green-600 text-white">Buy Now</button>
@else
<button class="bg-red-600 text-white">Buy Now</button>
@endif
Conditional Execution
// ✅ Execute code based on feature state
Feature::when('new-dashboard',
fn () => $this->renderNewDashboard(),
fn () => $this->renderOldDashboard(),
);
// ✅ With rich values
Feature::when('purchase-button',
fn ($variant) => view('buttons.' . $variant),
fn () => view('buttons.default'),
);
// ✅ Unless (inverse)
Feature::unless('legacy-mode',
fn () => $this->useModernApi(),
fn () => $this->useLegacyApi(),
);
Blade Directives
{{-- ✅ Basic feature check --}}
@feature('new-dashboard')
<x-new-dashboard :user="$user" />
@else
<x-legacy-dashboard :user="$user" />
@endfe
Установить laravel-feature-flags в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл laravel-feature-flags?
Best practices for Laravel Pennant feature flags including defining features, checking activation, scoping, rich values for A/B testing, and gradual rollouts.
Как установить скилл laravel-feature-flags?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл laravel-feature-flags запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic