laravel/pennant
Laravel Pennant is a simple, lightweight feature flag library for Laravel. Define and evaluate feature toggles, control rollouts, and experiment safely across environments. Official docs available at laravel.com/docs/pennant.
Laravel Pennant is a lightweight, Laravel-native feature flagging solution that aligns well with Laravel’s ecosystem. Its modular design (drivers, scopes, hooks) enables seamless integration into existing Laravel applications, particularly those using Laravel 11+. The package leverages Laravel’s service container, caching, and database layers, reducing friction for adoption.
Key architectural strengths:
user, tenant, role) for granular control.EnsureFeaturesAreActive) for route/endpoint-level feature gating.@feature, @featureany) for frontend integration.FeatureUpdated) for reactive workflows.php artisan pennant:install) and basic configuration.FeatureDriver interface.Feature::bool(), Feature::string()).| Risk Area | Assessment |
|---|---|
| Database Schema | Migration is straightforward but may conflict with existing features tables. |
| Caching Strategy | Cache invalidation is automatic but requires Redis/Memcached for high-scale use. |
| Performance | Bulk operations (e.g., Feature::set()) are optimized, but high-traffic apps may need driver tuning. |
| Scope Complexity | Custom scopes require careful implementation to avoid race conditions. |
| Laravel Version Lock | Tightly coupled to Laravel 11–13; may need adjustments for older/new versions. |
user.tenant.environment)? If so, how will conflicts be resolved?Feature::bool() in unit tests.)Pennant is optimized for Laravel monoliths and microservices using Laravel’s HTTP layer. It integrates natively with:
Feature model for persistence.@feature) and JavaScript hooks (via API).FeatureUpdated events.Non-Laravel Stacks:
| Phase | Tasks |
|---|---|
| Assessment | Audit existing feature flags (hardcoded, config, external services). |
| Pilot | Migrate non-critical flags to Pennant in a staging environment. |
| Core Integration | Run php artisan pennant:install, configure config/pennant.php. |
| Frontend Sync | Replace hardcoded checks with @feature directives or API calls. |
| Middleware Rollout | Apply EnsureFeaturesAreActive to protected routes. |
| Testing | Validate flag behavior via unit/integration tests (mock scopes). |
| Monitoring | Set up alerts for FeatureUpdated events or cache misses. |
FeatureManager, FeatureDriver, or Feature model for bespoke logic.laravel/pennant) with minimal overhead.php artisan pennant:list to inspect active flags.php artisan cache:clear or Feature::flushCache().Feature::scope().Feature::get() calls; consider caching layers.Feature::set()) are optimized; avoid per-request DB hits.| Scenario | Mitigation Strategy |
|---|---|
| Database Downtime | Use Redis driver as primary; fall back to in-memory cache. |
| Cache Eviction | Implement FeatureUpdated listeners to repopulate cache. |
| Misconfigured Scopes | Use defaultScope() to avoid null scope errors. |
| Flag Leakage | Restrict Feature::get() access via middleware or decorators. |
| Migration Failures | Backup database before running pennant:install; use rollback migrations. |
Feature::bool('flag.name')).Feature::get() cache performance.features table load via Laravel Debugbar.FeatureUpdated events for auditability.@feature directive rendering time in Blade.FeatureException occurrences.How can I help you explore Laravel packages today?