Download the PHP package turtlemilitia/laravel-featureflags without Composer

On this page you can find all versions of the php package turtlemilitia/laravel-featureflags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-featureflags

Laravel Feature Flags

A Laravel package for feature flag evaluation with local caching. Designed to work with the Turtle Militia feature flags dashboard.

Requirements: PHP 8.2+ and Laravel 11 or 12.

Table of Contents

Features

Installation

Quick Start

Add your API credentials to .env:

Check a flag:

Configuration

Publish the config file to customize settings:

Most settings work via environment variables:

Variable Description
FEATUREFLAGS_API_URL API endpoint
FEATUREFLAGS_API_KEY Your environment API key
FEATUREFLAGS_WEBHOOK_ENABLED Enable webhook endpoint
FEATUREFLAGS_WEBHOOK_SECRET Webhook signature secret
FEATUREFLAGS_TELEMETRY_ENABLED Send evaluation data to dashboard
FEATUREFLAGS_TELEMETRY_ASYNC Dispatch telemetry via queue jobs
FEATUREFLAGS_TELEMETRY_QUEUE Queue name for async telemetry
FEATUREFLAGS_LOCAL_MODE Use locally-defined flags
FEATUREFLAGS_HOLD_UNTIL_CONSENT Hold telemetry until user consents
FEATUREFLAGS_CONSENT_TTL_DAYS Days before consent expires (365)

Usage

In Blade templates:

Context

Context is resolved automatically from the authenticated user. Implement HasFeatureFlagContext on your User model:

Any model can implement the interface and be passed as context:

You can also pass context explicitly:

Nested Traits

Context supports nested arrays with dot notation in targeting rules. This is useful for targeting based on relationships:

Then target with dot notation in your rules: subscription.plan.name equals "pro" or subscription.status equals "active".

Targeting Rules

The dashboard supports these operators for targeting rules:

Operator Description Example
equals Exact match plan equals "pro"
not_equals Not equal plan not_equals "free"
contains String contains email contains "@company.com"
not_contains String does not contain email not_contains "test"
gt Greater than age gt 18
gte Greater than or equal orders gte 10
lt Less than balance lt 100
lte Less than or equal balance lte 1000
in Value in array country in ["US","GB","CA"]
not_in Value not in array country not_in ["CN","RU"]
matches_regex Regex pattern match email matches_regex ".*@company\.com$"
semver_gt Version greater than app_version semver_gt "2.0.0"
semver_gte Version greater or equal app_version semver_gte "2.0.0"
semver_lt Version less than app_version semver_lt "3.0.0"
semver_lte Version less or equal app_version semver_lte "2.5.0"
before_date Date is before created_at before_date "2025-01-01"
after_date Date is after trial_end after_date "2025-01-01"
percentage_of Percentage of attribute values id percentage_of 50

Example rule (configured in dashboard):

Version-Based Targeting

Semver operators are useful when your Laravel app serves as an API backend for mobile apps or versioned frontends. To use them, create a version resolver that provides version traits to the context.

Create a class implementing ResolvesVersion:

Register it in your config:

The resolved traits are automatically merged into every context, so you can create rules like app_version semver_gte "2.0.0" in your dashboard without passing the version explicitly.

Percentage Rollouts

Rollouts use sticky bucketing based on the flag key and context ID. The same context will always get the same result for a given flag.

Attribute-Based Rollouts

The percentage_of operator enables attribute-based percentage rollouts within targeting rules. Unlike global percentage rollouts, this lets you target a percentage of users based on any attribute:

This rule matches 50% of pro users:

Experiments

Experiments enable A/B testing with automatic variant assignment. When you create an experiment on a flag in the dashboard, the package automatically assigns users to variants deterministically.

How It Works

  1. Define variants on a flag in the dashboard (e.g., ["blue", "red", "green"] for a button color test)
  2. Create an experiment on that flag with a goal event (e.g., purchase)
  3. Start the experiment - the package now randomly assigns users to variants
  4. Track conversions - conversions are automatically attributed to the variant each user saw

Variant Assignment

When an experiment is running, the package uses deterministic bucketing to assign users to variants:

The assignment is:

Evaluation Priority

Flags are evaluated in this order:

  1. Disabled - Returns default value
  2. Targeting rules - If user matches a rule, returns rule value (rules always win)
  3. Experiment - If experiment is running, assigns user to a variant
  4. Percentage rollout - If configured, applies rollout logic
  5. Default value - Returns the flag's default

This means targeting rules take precedence over experiments. Use this to:

Traffic Percentage (Holdout Groups)

Experiments support traffic percentage for holdout groups:

Users in the holdout group are excluded from the experiment entirely and always see the default value.

Conversion Attribution

Conversions are automatically linked to the flags evaluated in the same request:

The package tracks all flag evaluations during a request and includes them when sending conversion events. No manual attribution needed.

Segments

Segments are reusable user groups defined in the dashboard:

Segments support all the same operators as regular trait conditions.

Webhooks

Configure your dashboard to send webhooks to /webhooks/feature-flags. The package automatically invalidates and refreshes the cache when flags change.

Set FEATUREFLAGS_WEBHOOK_SECRET in your .env for signature verification. The secret is required - requests are rejected with 401 if unset.

To sync manually:

Or programmatically:

Fallback Behavior

When the API is unavailable:

Configure in config/featureflags.php:

Conversion Tracking

Track conversions for A/B test analysis:

Automatic Flag Attribution

Every conversion automatically includes all flags evaluated during the current request. The dashboard uses this to:

No manual flag specification needed - the package handles attribution automatically.

Explicit Attribution

For cases where you need to attribute a conversion to a specific flag (e.g., async jobs, webhooks):

Error Tracking

Errors are automatically correlated with evaluated feature flags, helping identify if a new feature is causing issues. Requires FEATUREFLAGS_TELEMETRY_ENABLED=true.

Setup

Register the service provider:

Once registered:

  1. Every flag evaluation is tracked during the request
  2. When an exception occurs, all evaluated flags are attached
  3. Third-party error trackers (Sentry, Bugsnag, Flare) receive the flag context via Laravel's Context facade
  4. Your dashboard shows error rates correlated by flag value

What Gets Tracked

Monitor Wrapper

For critical code paths:

If the callback throws, the error is tracked with the exact flag value before global exception handling.

Manual Tracking

Configuration

Supported Error Trackers

Provider Package Automatic
Laravel Nightwatch laravel/nightwatch
Sentry sentry/sentry-laravel
Bugsnag bugsnag/bugsnag-laravel
Flare spatie/laravel-ignition

Automatic integration requires Laravel 11+ (uses the Context facade). On Laravel 10, use Feature::getEvaluatedFlags() to wire up your error tracker manually.

Local Development & Testing

Enable local mode for offline development and testing:

Define flags in config/featureflags.php under local.flags:

Export current flags from the API for offline work:

Mocking the Facade

For unit tests, mock specific flag checks:

Testing with Context

To test that rules evaluate correctly for different contexts:

Testing Percentage Rollouts

Rollouts are deterministic - the same context ID always gets the same result for a given flag:

Observability

Events

Optional Laravel events for monitoring. Disabled by default.

Or per-event in config/featureflags.php:

Event Payload
FlagEvaluated flagKey, value, contextId, matchReason
FlagSyncCompleted flagCount, segmentCount, durationMs
TelemetryFlushed type, eventCount, success, durationMs

Performance

Cache Warming

Pre-warm the cache on deployment:

Sampling

Reduce telemetry volume for high-traffic sites:

Flush Rate Limiting

Queue telemetry flushes to avoid hitting your plan's rate limit:

Async Mode (Recommended)

By default, telemetry is sent synchronously at the end of each request. Enable async mode to dispatch telemetry to a queue job instead, preventing API latency from affecting response times.

Or in config:

Requirements:

Benefits:

GDPR Compliance

For GDPR-compliant telemetry, enable "hold until consent" mode. Feature flag evaluation works immediately, but telemetry is queued until the user consents.

Usage

How It Works

  1. First visit: Device ID cookie (ff_device_id) is set for consistent bucketing
  2. Flag checks: Evaluation works normally, telemetry events are queued
  3. User consents: grantConsent() flushes queued events and sets consent cookie (ff_telemetry_consent)
  4. Subsequent visits: Consent cookie is detected, telemetry flows normally

Configuration

After consent_ttl_days, the consent cookie expires and the user will need to re-consent.

License

MIT

Support


All versions of laravel-featureflags with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0|^12.0
illuminate/cache Version ^11.0|^12.0
illuminate/http Version ^11.0|^12.0
guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package turtlemilitia/laravel-featureflags contains the following files

Loading the files please wait ...