Skip to main content

Laravel Pennant Feature Flags

Implement feature flags with Laravel Pennant for gradual rollouts, A/B testing, user segmentation, and safe deployment of new features.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Implement a feature flag system using Laravel Pennant for a multi-tenant SaaS project management tool application with 15,000 users. The goal is to safely roll out 5 new features with gradual percentage-based rollout with team targeting. Use Laravel 11 with Pennant. Build it: 1) Install and configure Pennant: set up the database store driver, configure the default scope (User model), and create the service provider registration. Define the first 5 feature flags with descriptive names following the convention kebab-case with category prefix: ui-new-dashboard, billing-annual-plans. 2) Implement feature definitions with complex resolution logic: create a Feature class for new-ai-assistant-panel that resolves based on user plan tier (Pro+), account age (> 30 days), and 20% random sampling — implement percentage-based rollouts using Lottery, team/organization-based targeting, user attribute targeting (plan tier, signup date, geography), and an override system for internal testing. 3) Build a feature flag dashboard in Filament 3: create an admin page that lists all features, their activation status across user segments, allows manual activation/deactivation per user or globally, shows activation count, usage frequency, and error rate per feature, and provides a kill-switch that instantly deactivates a feature for all users. 4) Implement Blade integration: use @feature and @endfeature directives in views, create middleware that redirects users without access to a a waiting list signup page, and build a JavaScript bridge that exposes active features to the frontend via a meta tag or API endpoint. 5) Create an A/B testing pattern: define a feature with 3 (control, variant-a, variant-b) variants (not just on/off), assign users consistently to variants using deterministic hashing, track signup completion, upgrade to paid, and 7-day retention per variant, and build a results comparison report. 6) Add deployment safety: implement a canary deployment pattern where a new feature is enabled for 5% of users first, monitored for 24 hours, then gradually increased. Create a Pennant-aware health check that correlates error rate spikes with recently activated features. 7) Write tests: test feature resolution logic with Feature::define() in tests, use Feature::activate() and Feature::deactivate() for test isolation, and verify that both feature-on and feature-off code paths are covered.

What this prompt does

This prompt makes the AI build a feature-flag system with Laravel Pennant, scoped by [user_count] users and [feature_count] features on Laravel [laravel_version], following the [rollout_strategy] you choose. It configures the [storage_driver] store, defines flags using a [naming_convention], and implements complex resolution for [primary_feature] based on [resolution_criteria] — percentage rollouts via Lottery, organization targeting, and attribute targeting. Stating the user count and rollout strategy lets the AI design real gating rather than a boolean toggle.

The structure works because safe rollouts depend on the controls this prompt names. An [admin_panel] dashboard surfaces [metrics_to_track] and a kill-switch; Blade @feature directives and a [fallback_page] handle gating in views; and an A/B pattern with [variant_count] variants assigns users deterministically and tracks [conversion_events]. The canary step rolls out to [canary_percentage] first, watches for [monitoring_period], then expands — with tests using Feature::define(), activate(), and deactivate() for isolation. Stating [user_count] and the [storage_driver] lets the AI pick resolution logic that performs at your scale instead of recomputing flags on every request. The Blade @feature directives plus a JavaScript bridge expose the same flags to both server-rendered views and the frontend, and the Pennant-aware health check correlates error-rate spikes with recently activated features so a bad rollout is easy to spot.

When to use it

  • You want to ship features behind a flag and roll out gradually
  • You need percentage-based rollouts plus team or plan-tier targeting
  • You want a kill-switch to instantly disable a risky feature for everyone
  • You are running A/B tests and need deterministic, consistent variant assignment
  • You want a canary deployment that monitors error rate before expanding
  • You need an admin dashboard to toggle features per user or globally

Example output

The AI returns Pennant configuration, feature definitions with Lottery-based percentage logic and attribute targeting, an [admin_panel] dashboard listing features with activation status and a kill-switch, Blade @feature/@endfeature usage plus middleware redirecting to [fallback_page], a JavaScript bridge exposing active features, an A/B testing pattern with deterministic hashing across [variant_count] variants, a canary rollout starting at [canary_percentage], and tests covering both feature-on and feature-off paths.

Pro tips

  • Keep [naming_convention] consistent (category-prefixed kebab-case) so flags stay discoverable as [feature_count] grows
  • Make variant assignment deterministic via hashing — if it is random per request, your A/B data is worthless
  • Define [resolution_criteria] as concrete attributes (plan tier, account age, sample percentage) the AI can resolve
  • Always implement the kill-switch; it is the difference between a bad deploy and an outage
  • Set [canary_percentage] and [monitoring_period] conservatively for risky features and widen only after the metrics hold
  • Test both code paths explicitly with Feature::activate()/deactivate() so the off-path does not rot
  • Track [metrics_to_track] per feature from day one so you can tell whether a rollout is actually safe to widen
  • Use the [fallback_page] redirect for gated routes so users without access land somewhere useful rather than on an error

Frequently Asked Questions

Does Pennant support percentage-based rollouts in this prompt?
Yes. The primary feature uses Lottery for percentage rollouts, combined with team targeting and user-attribute targeting such as plan tier and account age. You control the mix through `[resolution_criteria]` and `[rollout_strategy]`.
How does the A/B testing variant assignment stay consistent?
Users are assigned to one of `[variant_count]` variants using deterministic hashing, so the same user always lands in the same variant across requests. The prompt then tracks `[conversion_events]` per variant for a results comparison; consistency is essential or the data becomes noise.
What does the kill-switch actually do?
The dashboard provides a control that instantly deactivates a feature for all users, regardless of their targeting rules. It is the safety mechanism for shipping risky features, letting you cut a feature without a redeploy if error rates spike.
Which admin panel does it integrate with?
Whatever you set in `[admin_panel]`, defaulting to Filament 3. The dashboard lists features, shows `[metrics_to_track]` per feature, allows per-user or global toggling, and exposes the kill-switch.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support