Laravel Pennant

A simple, lightweight feature-flag package for Laravel applications

Library
Composer
vv1.26.0
591stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity84
Maintenance84
Community76
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture78
Code Quality80
Innovation68
Learning Curve82

Laravel Pennant is the official feature-flag package for Laravel, letting applications define named features and check whether they’re active for the current user or any other scope. It ships with in-memory array and database-backed drivers out of the box, so teams can start with zero-config flags in tests and local dev, then switch to persisted, per-user flag state in production without changing calling code.

Features are defined as closures or class-based Feature objects and can be checked via a fluent Feature::active() API, a @feature Blade directive, an HTTP middleware for gating routes, and Artisan commands for purging or listing flag state. Because it’s built on Laravel’s existing container, queue, and database abstractions, Pennant integrates directly with Eloquent scoping and Octane without extra glue code.

What You Get

  • A Feature facade with active(), activate(), deactivate(), and when() APIs for checking and mutating flags
  • Built-in Array driver (in-memory, ideal for tests) and Database driver (persisted, per-scope) with a pluggable driver contract for custom stores
  • A @feature / @featureany Blade directive for gating template output
  • An HTTP middleware for restricting routes based on active features
  • Artisan commands (pennant:purge, etc.) for managing stored flag state
  • First-class support for scoping flags to any model, not just the authenticated user

Common Use Cases

  • Rolling out a new feature to a percentage of users or a specific customer segment
  • Gating in-development functionality behind a flag during incremental delivery
  • Running A/B or canary tests by scoping a feature to cohorts of Eloquent models
  • Toggling behavior in automated tests via the fast in-memory Array driver

Under The Hood

Architecture — Pennant centers on FeatureManager (src/FeatureManager.php), which resolves named feature definitions and delegates state reads/writes to a configured Driver (src/Drivers/ArrayDriver.php, DatabaseDriver.php), wrapped by a caching Decorator.php to avoid redundant driver hits within a request. PendingScopedFeatureInteraction.php implements the fluent, scope-aware query builder (Feature::for($user)->active()), and PennantServiceProvider.php wires the manager, Blade directive, middleware, and Artisan commands into the Laravel container. Tech Stack — Pure PHP 8.1+ built on Laravel’s illuminate/* contracts (console, container, database, queue, support) and Symfony console/finder; the Database driver persists to a features table via a bundled migration in database/migrations. Code Quality — A large tests/Feature suite (ArrayDriverTest, DatabaseDriverTest, FeatureManagerTest, FeatureMiddlewareTest, HasFeatureTest, PurgeCommandTest, and more) exercises both drivers, middleware, Blade directive, and console commands; the package also ships a workbench/ Laravel skeleton app used by Orchestra Testbench for integration-style testing. API Design — The API favors Laravel idioms: a facade, a fluent scoped-query builder, attribute-based feature classes (src/Attributes), and helper functions (src/helpers.php), which keeps the learning curve low for existing Laravel developers while remaining a thin, dependency-light layer over the framework’s existing container and database services.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search