Laravel Pennant is a first-party, simple, and lightweight feature flag package for Laravel applications. It enables developers to incrementally roll out new features, conduct A/B testing, and implement trunk-based development strategies with confidence[1][3].
Key Features of Laravel Pennant
- Feature Flag Management: Allows defining features as flags that can be toggled on or off or assigned rich values beyond simple booleans (e.g., different UI themes or button colors)[1].
- Scopes: Supports scoping feature flags to specific users, models, or other contexts, with customizable serialization of scope identifiers[1].
- Storage Drivers: Comes with built-in drivers for storing feature flag states in an in-memory array or persistently in a relational database (default)[1].
- Eager Loading: Supports eager loading of feature flags to optimize performance when checking flags for multiple users or scopes[1].
- Blade Integration: Provides Blade directives for conditionally rendering content based on feature flags, including support for complex logic and rich feature values[1][4].
- Testing and Extensibility: Includes support for testing feature flags and adding custom drivers if needed[1].
Installation and Setup
1. Install via Composer:
composer require laravel/pennant
2. Publish configuration and migration files:
php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider"
3. Run migrations to create the `features` table:
php artisan migrate
After setup, you define features in your application code and check their status using the `Feature` facade, for example:
php
if (Feature::active('telecommunications')) {
// Feature enabled
} else {
// Feature disabled
}
This abstraction allows you to change how feature flags are stored or resolved without modifying application logic[1][3].
Use Cases
- Gradual rollout of new features to subsets of users
- A/B testing different UI elements or experiences
- Managing feature availability in different environments or user roles
- Supporting non-boolean feature flags with rich values like themes or colors
Additional Resources
- Official Laravel documentation provides detailed guides on defining features, scoping, eager loading, and more[1].
- Video tutorials (e.g., by Aaron Francis) offer practical walkthroughs of Laravel Pennant usage[4].
- Community articles and tutorials explain benefits and implementation patterns[3][5][6].
In summary, Laravel Pennant is a robust and developer-friendly solution for feature flag management in Laravel, promoting maintainable, flexible, and performant feature rollouts. It integrates tightly with Laravel's ecosystem and supports advanced use cases like scoped and rich-value flags.
Citations:
[1] https://laravel.com/docs/12.x/pennant
[2] https://github.com/laravel/pennant
[3] https://www.honeybadger.io/blog/a-guide-to-feature-flags-in-laravel/
[4] https://www.youtube.com/watch?v=EjLAaeHSPWY
[5] https://laravel-news.com/feature-flags-with-laravel-pennant
[6] https://hackernoon.com/how-to-manage-feature-flags-with-laravel-pennant
[7] https://www.reddit.com/r/laravel/comments/10yto7q/laravel_pennant_simple_and_lightweight_feature/
[8] https://dev.to/saurabh-dhariwal/how-to-manage-feature-flags-with-laravel-pennant-in-2024-1phb