Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pennant Laravel Package

laravel/pennant

Laravel Pennant is a simple, lightweight feature flag library for Laravel. Define and evaluate feature flags to safely roll out, test, and target functionality in your app. Official docs available on the Laravel website.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Feature Flag Management: Pennant is a lightweight, Laravel-native solution for feature flags, aligning well with Laravel’s ecosystem. It supports scoped flags (e.g., user-specific, role-based) and integrates seamlessly with Laravel’s service container, caching, and middleware.
  • Extensibility: Supports custom drivers (e.g., Redis, database) and hooks (e.g., before callbacks), making it adaptable for complex use cases like A/B testing or gradual rollouts.
  • Performance: Optimized for high-traffic apps (e.g., bulk updates, cache invalidation) and supports PHP 8.4+ with type safety improvements.
  • Middleware Integration: Built-in EnsureFeaturesAreActive middleware enables route/endpoint-level feature gating without manual checks.

Integration Feasibility

  • Laravel-Centric: Designed for Laravel (v11+), with zero dependencies beyond Laravel core. No conflicts with existing packages (e.g., feature() helper is namespaced).
  • Database Agnostic: Works with any PDO-supported database (MySQL, PostgreSQL, SQLite) and supports multi-database setups.
  • Cache Compatibility: Integrates with Laravel’s cache system (Redis, Memcached, etc.) for low-latency flag resolution.
  • Blade Directives: Provides @feature and @featureany directives for templating, reducing boilerplate.

Technical Risk

  • Migration Complexity: Requires database migrations for flag storage (unless using in-memory driver). Schema changes may need backward-compatibility handling.
  • Scope Granularity: Overly complex scopes (e.g., nested conditions) could introduce performance overhead if not optimized (e.g., caching strategies).
  • Cache Invalidation: Improper cache flushing (e.g., during bulk updates) may cause stale flag values. Pennant mitigates this with flushCache() hooks, but custom drivers must implement this correctly.
  • Legacy Code Impact: Existing feature flag logic (e.g., hardcoded if (config('flags.new_feature'))) will need refactoring to use Pennant’s API.

Key Questions

  1. Flag Storage: Will flags be stored in the database (default) or a cache layer (e.g., Redis)? Does the team need audit trails (e.g., who enabled/disabled flags)?
  2. Scope Strategy: How will scopes be defined? Simple (e.g., user_id) or complex (e.g., user_role AND geo_region)? Will dynamic scopes (e.g., based on request data) be needed?
  3. Performance: For high-traffic endpoints, will cache warming or preloading be required to avoid cache misses?
  4. Rollback Plan: How will the team handle flag-related incidents? Does Pennant’s before hooks support automatic rollback logic?
  5. Testing: Will feature flag tests require mocking? Pennant supports testing helpers (e.g., Pennant::fake()), but integration tests may need adjustments.
  6. Multi-Tenant: If the app is multi-tenant, how will tenant-specific flags be scoped? Pennant supports this via custom scopes, but the implementation must align with the tenant strategy.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Pennant is optimized for Laravel, with native support for:
    • Service Container: Flags are resolved via Laravel’s DI.
    • Middleware: EnsureFeaturesAreActive integrates with Laravel’s middleware pipeline.
    • Events: FeatureUpdated events trigger observables (e.g., logging, analytics).
    • Artisan Commands: pennant:purge, pennant:load for CLI management.
  • Cache Backends: Works with Redis, Memcached, or file cache for low-latency flag resolution.
  • Database: Uses Eloquent-like migrations (but not Eloquent models), so it’s lightweight and avoids ORM overhead.

Migration Path

  1. Assessment Phase:
    • Audit existing feature flag implementations (e.g., config files, environment variables, third-party services).
    • Define scope requirements (e.g., user-based, role-based, percentage rollouts).
  2. Pilot Phase:
    • Start with non-critical features (e.g., experimental UI elements).
    • Replace hardcoded flags with Pennant’s feature() helper or middleware.
    • Example:
      // Before (config-based)
      if (config('features.new_ui')) { ... }
      
      // After (Pennant)
      if (feature('new_ui')->isActive()) { ... }
      
  3. Full Migration:
    • Database Setup: Run php artisan pennant:install to create the flags table.
    • Middleware Integration: Add EnsureFeaturesAreActive to routes requiring flags.
    • Blade Directives: Replace @if(config('features.x')) with @feature('x').
    • Testing: Update tests to use Pennant’s testing helpers (e.g., Pennant::fake()).
  4. Deprecation:
    • Phase out legacy flag systems (e.g., config files) via deprecation warnings.
    • Use Pennant’s purge command to clean up old flag data.

Compatibility

  • Laravel Versions: Supports Laravel 11–13 (as of v1.22.0). For older versions, use v1.x.
  • PHP Versions: Requires PHP 8.1+ (v1.18.4+ supports PHP 8.5).
  • Database Drivers: Works with MySQL, PostgreSQL, SQLite, SQL Server. Custom drivers can be added.
  • Cache Drivers: Compatible with all Laravel-supported cache backends.
  • Third-Party Conflicts: No known conflicts with popular Laravel packages (e.g., Spatie, Laravel Nova). The feature() helper is namespaced to avoid collisions.

Sequencing

  1. Infrastructure:
    • Install Pennant via Composer: composer require laravel/pennant.
    • Publish config: php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider".
    • Configure database/cache drivers in config/pennant.php.
  2. Core Integration:
    • Run migrations: php artisan migrate.
    • Set up initial flags via:
      • Artisan: php artisan pennant:load --features=flag1,flag2.
      • Seeder: Create a PennantSeeder to populate flags on php artisan db:seed.
  3. Application Layer:
    • Replace legacy flag checks with feature('flag')->isActive().
    • Add middleware to routes: Route::middleware(['web', 'pennant'])->group(...).
  4. Testing:
    • Update unit/integration tests to use Pennant::fake().
    • Add flag-specific tests (e.g., "Verify new_ui flag gates the dashboard").
  5. Monitoring:
    • Set up logging for flag updates (via FeatureUpdated events).
    • Monitor cache hit/miss ratios for performance tuning.

Operational Impact

Maintenance

  • Flag Management:
    • Flags can be updated via Artisan, seeder, or API (if extended). No need for manual config file edits.
    • Purge command (pennant:purge) cleans up unused flags.
  • Configuration:
    • Centralized in config/pennant.php (e.g., default driver, cache TTL).
    • Environment-specific flags: Use .env or scoped flags (e.g., feature('staging_only')->for('env', 'staging')).
  • Updates:
    • Pennant follows Laravel’s release cycle. Minor updates are low-risk (e.g., v1.x to v1.x).
    • Major version upgrades (e.g., v1.x to v2.x) may require migration scripts.

Support

  • Troubleshooting:
    • Flag Not Loading: Check cache (php artisan cache:clear), database connection, and migrations.
    • Scope Issues: Verify scope syntax (e.g., feature('x')->for('user_id', auth()->id())).
    • Performance: Use DB::enableQueryLog() to debug slow flag queries.
  • Documentation:
    • Official docs are Laravel-centric but lack deep-dive examples for complex scopes.
    • Community-driven GitHub issues cover common pitfalls (e.g., cache invalidation).
  • Vendor Lock-in:
    • Low risk: Pennant is MIT-licensed and open-source. Custom drivers allow migration to other systems if needed.

Scaling

  • Performance:
    • Cache Layer: Flags are cached by default (TTL configurable). For high traffic, consider Redis with a short TTL (e.g., 5 minutes).
    • Database: Bulk operations (e.g., `pennant
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport