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. Manage, evaluate, and roll out features safely across environments with an easy API and first-party integration, backed by official Laravel documentation.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

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:

  • Service Providers for configuration and bootstrapping.
  • Eloquent Models for persistence (supports database, cache, and in-memory drivers).
  • Middleware for route/feature gating.
  • Blade Directives for templating.
  • Events for observability (e.g., feature updates).
  • Decorators for dynamic flag resolution (scopes, types, and aliases).

Key Strengths:

  • Minimal Abstraction Overhead: Avoids heavy frameworks like LaunchDarkly or Flagsmith, focusing on simplicity.
  • Laravel-Centric: Native support for Laravel’s DI container, caching (Redis, Memcached), and query builder.
  • Extensibility: Supports custom drivers, scopes (e.g., user roles, geolocation), and serialization hooks.
  • Performance Optimizations: Batch operations (e.g., bulk updates), lazy loading, and cache-aware design.

Potential Gaps:

  • Advanced Analytics: Lacks built-in A/B testing or multivariate flagging (requires custom logic).
  • Multi-Tenancy: No native support for tenant-aware scopes (would need decorator customization).
  • Remote Config: No native integration with external flag services (e.g., Firebase Remote Config).

Integration Feasibility

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:

  • Laravel Framework: Core functionality relies on Laravel’s service container, Eloquent, and caching.
  • PHP 8.1+: Required for modern type hints and attributes (e.g., @featureany directive).
  • Database: Defaults to Eloquent; custom drivers need schema migrations.

Technical Risk

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:

  1. Scope Complexity: Will flags require custom scopes (e.g., multi-dimensional, tenant-aware)? If so, how will decorators be extended?
  2. Driver Choice: Will the team use the default database driver or a custom one (e.g., DynamoDB)? What are the trade-offs?
  3. Observability: Are feature usage events (e.g., FeatureUpdated) critical for analytics? If so, how will they be logged?
  4. Rollout Strategy: Will flags be used for canary releases, A/B testing, or simple toggles? Pennant lacks native A/B support.
  5. Compliance: Are there audit requirements for flag changes (e.g., who toggled what and when)? Custom event listeners may be needed.
  6. CI/CD Integration: How will flag management fit into deployment pipelines (e.g., GitOps for feature toggles)?

Integration Approach

Stack Fit

Laravel Pennant is optimized for Laravel monoliths and microservices using Laravel’s ecosystem. It fits best in:

  • Traditional Laravel Apps: Especially those using Eloquent, Blade, and middleware.
  • API-First Applications: For dynamic feature gating in routes/controllers.
  • Serverless/Lambda: With Redis caching (avoid database cold starts).
  • Hybrid Stacks: Where Laravel coexists with React/Vue (via API endpoints).

Less Ideal For:

  • Non-Laravel PHP Apps: Requires Laravel’s service container and helpers.
  • Edge/Serverless Runtimes: Without Redis/Memcached, performance may degrade.
  • Polyglot Persistence: If flags must live in a non-SQL database (e.g., MongoDB).

Migration Path

Phase 1: Proof of Concept (2–4 weeks)

  1. Setup:
    • Install via Composer: composer require laravel/pennant.
    • Publish config: php artisan vendor:publish --tag="pennant-config".
    • Run migrations: php artisan pennant:install.
  2. Core Integration:
    • Replace hardcoded feature checks with Pennant::feature('flag-name').
    • Test with a single flag in a non-critical route.
  3. Validation:
    • Verify cache invalidation with php artisan pennant:flush.
    • Test middleware gating: Route::middleware(['pennant'])->group(...);.

Phase 2: Full Rollout (4–8 weeks)

  1. Scope Expansion:
    • Implement custom scopes (e.g., user()->isAdmin()).
    • Extend decorators for complex logic (e.g., Feature::decorateWith(TenantScope::class)).
  2. Persistence:
    • Migrate existing feature toggles to Pennant’s database.
    • Configure caching (Redis recommended for production).
  3. Observability:
    • Listen to FeatureUpdated events for logging/auditing.
    • Add Blade directives for frontend flags: @feature('flag').
  4. Testing:
    • Unit tests for flag resolution (mock Pennant facade).
    • Integration tests for middleware and cache behavior.

Phase 3: Optimization (Ongoing)

  1. Performance Tuning:
    • Benchmark Feature::set() for bulk updates.
    • Adjust cache TTL based on flag volatility.
  2. Advanced Patterns:
    • Implement feature rollouts with before hooks (e.g., analytics ping).
    • Use @featureany for dynamic flag checks in Blade.
  3. Documentation:
    • Internal runbook for flag management (e.g., "How to toggle new-payments").
    • API docs for custom scopes/decorators.

Compatibility

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.

Sequencing

Recommended Order of Implementation:

  1. Database Setup: Run migrations and seed initial flags.
  2. Core Flags: Replace 2–3 critical feature toggles (e.g., new-ui, payments-v2).
  3. Middleware: Protect routes with EnsureFeaturesAreActive.
  4. **
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope