home / skills / laravel / boost / pennant-development

pennant-development skill

/.ai/pennant/skill/pennant-development

This skill helps you manage Laravel Pennant feature flags, enabling targeted rollouts, A/B testing, and conditional UI with ease.

npx playbooks add skill laravel/boost --skill pennant-development

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.6 KB
---
name: pennant-development
description: "Manages feature flags with Laravel Pennant. Activates when creating, checking, or toggling feature flags; showing or hiding features conditionally; implementing A/B testing; working with @feature directive; or when the user mentions feature flags, feature toggles, Pennant, conditional features, rollouts, or gradually enabling features."
license: MIT
metadata:
  author: laravel
---
# Pennant Features

## When to Apply

Activate this skill when:

- Creating or checking feature flags
- Managing feature rollouts
- Implementing A/B testing

## Documentation

Use `search-docs` for detailed Pennant patterns and documentation.

## Basic Usage

### Defining Features

<!-- Defining Features -->
```php
use Laravel\Pennant\Feature;

Feature::define('new-dashboard', function (User $user) {
    return $user->isAdmin();
});
```

### Checking Features

<!-- Checking Features -->
```php
if (Feature::active('new-dashboard')) {
    // Feature is active
}

// With scope
if (Feature::for($user)->active('new-dashboard')) {
    // Feature is active for this user
}
```

### Blade Directive

<!-- Blade Directive -->
```blade
@feature('new-dashboard')
    <x-new-dashboard />
@else
    <x-old-dashboard />
@endfeature
```

### Activating / Deactivating

<!-- Activating Features -->
```php
Feature::activate('new-dashboard');
Feature::for($user)->activate('new-dashboard');
```

## Verification

1. Check feature flag is defined
2. Test with different scopes/users

## Common Pitfalls

- Forgetting to scope features for specific users/entities
- Not following existing naming conventions

Overview

This skill manages feature flags using Laravel Pennant to help you create, check, toggle, and roll out features safely. It activates when you work with feature flags, the @feature Blade directive, A/B tests, conditional features, or gradual rollouts. It focuses on predictable, scoped feature control inside Laravel applications.

How this skill works

The skill inspects code and commands related to defining Feature::define(), Feature::active(), and Feature::for(...)->active()/activate()/deactivate(). It guides you through scoping flags to users or entities, using the @feature Blade directive, and implementing rollout and A/B testing patterns. It also verifies that flags are defined and recommends test scenarios for different scopes.

When to use it

  • When creating or defining new feature flags with Feature::define
  • When checking or toggling flags in controllers, middleware, or services
  • When implementing conditional UI with the @feature Blade directive
  • When rolling out features gradually or configuring A/B tests
  • When scoping feature access to users, roles, or custom entities

Best practices

  • Always define flags centrally and document naming conventions to avoid collisions
  • Scope flags explicitly (e.g., Feature::for($user)) for per-user or per-entity behavior
  • Write automated tests that assert behavior with and without the flag for relevant user scopes
  • Use concise, descriptive flag names that reflect intent (e.g., new-dashboard, payments-v2)
  • Disable or remove flags after rollout and keep a cleanup plan for stale flags

Example use cases

  • Enable a new dashboard only for admin users while leaving it hidden for others
  • Use Feature::for($user)->activate() to grant early access to beta testers
  • Wrap new UI in @feature('new-dashboard') to render alternative components conditionally
  • Implement A/B tests by toggling feature flags for segments of users and measuring outcomes
  • Perform staged rollouts: activate for a percentage of users, then specific roles, then all users

FAQ

How do I test flagged behavior across users?

Define the flag and write tests that set different scopes with Feature::for($user)->activate() and assert both active and inactive outcomes.

What if I forget to scope a flag?

Unscoped flags apply globally. To avoid mistakes, prefer explicit scoping and include code reviews that check for Feature::for(...) when per-user behavior is required.