laravel/pennant
Laravel Pennant is a simple, lightweight feature flag library for Laravel. Manage, evaluate, and roll out features safely across environments with an easy API and first-party integration, backed by official Laravel documentation.
Laravel Pennant is a lightweight, Laravel-native feature flagging solution designed for seamless integration into Laravel applications. Its architecture aligns well with Laravel’s ecosystem, leveraging:
Key Strengths:
Potential Gaps:
| Dimension | Feasibility | Risks |
|---|---|---|
| Laravel Version Support | v10–v13 (as of v1.23.0) | Downgrade required for pre-v10 apps; upgrade path for v14+ untested. |
| Database Drivers | MySQL, PostgreSQL, SQLite (via Eloquent) | Custom drivers require additional dev effort. |
| Caching | Redis, Memcached, file cache (Laravel’s cache system) | Cache invalidation must be manually configured for custom drivers. |
| Authentication Scopes | Integrates with Laravel’s auth (e.g., Auth::user()->id) |
Custom scopes (e.g., IP, device) need decorator extensions. |
| Middleware | Built-in EnsureFeaturesAreActive middleware |
Route-level gating may conflict with existing middleware order. |
| Blade/Templating | @feature('flag') directive |
No server-side rendering (SSR) support (e.g., for Next.js/Laravel mix). |
| Testing | Mockable facade (Pennant::feature()) |
Integration tests may need stubs for database/cache interactions. |
Critical Dependencies:
@featureany directive).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Cache Invalidation | High | Monitor flushCache() calls; test under load with Redis/Memcached. |
| Schema Migrations | Medium | Use php artisan pennant:install; validate migrations for custom drivers. |
| Scope Validation | Medium | Test edge cases (e.g., null scopes, complex types) with Decorator::typeAllowsScope(). |
| Performance Under Load | Low | Benchmark bulk operations (e.g., Feature::set()) with 10K+ flags. |
| Upgrade Path | Low | Follow Laravel’s upgrade guides; Pennant’s changelog highlights breaking changes. |
| Security | Low | Flags are stored in DB/cache; no direct exposure to end-users. |
Key Questions for the TPM:
FeatureUpdated) critical for analytics? If so, how will they be logged?Laravel Pennant is optimized for Laravel monoliths and microservices using Laravel’s ecosystem. It fits best in:
Less Ideal For:
composer require laravel/pennant.php artisan vendor:publish --tag="pennant-config".php artisan pennant:install.Pennant::feature('flag-name').php artisan pennant:flush.Route::middleware(['pennant'])->group(...);.user()->isAdmin()).Feature::decorateWith(TenantScope::class)).FeatureUpdated events for logging/auditing.@feature('flag').Pennant facade).Feature::set() for bulk updates.before hooks (e.g., analytics ping).@featureany for dynamic flag checks in Blade.new-payments").| Component | Compatibility | Workarounds |
|---|---|---|
| Laravel 10–13 | ✅ Native support | Downgrade/upgrade as needed. |
| PHP 8.1–8.5 | ✅ Full support | Use config('pennant.php_version') to enforce. |
| Redis/Memcached | ✅ Cache driver support | Configure cache.default in .env. |
| Custom Drivers | ⚠️ Requires extension | Implement Pennant\Contracts\Driver interface. |
| Queue Workers | ✅ Event listeners work with queues | Ensure FeatureUpdated events are dispatched. |
| Livewire/Alpine.js | ⚠️ Frontend flags need JS integration | Use Laravel Echo or custom JS to poll flags. |
| Docker/Kubernetes | ✅ Stateless with Redis | Persist cache externally; avoid local file cache. |
Recommended Order of Implementation:
new-ui, payments-v2).EnsureFeaturesAreActive.How can I help you explore Laravel packages today?