- Notifications
You must be signed in to change notification settings - Fork0
This package aims to provide a fully-featured, yet simple feature flag configuration through environment variables for Laravel 8+
License
rescaled/simple-feature
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Simple Feature allows you to define feature flags via environment variables and check for their state withinyour Laravel application. It also provides pre-defined middleware you can utilize for this use case.
You can install the package via composer:
composer require rescaled/simple-feature
Feature flags are defined in your environment file. They must be defined in snake case as well as being prefixed withFEATURE_
.
FEATURE_FIRST_TEST=trueFEATURE_SECOND_TEST=trueFEATURE_THIRD_TEST=falseFEATURE_FOURTH_TEST=false
You can directly access the package's methods as following.
SimpleFeature::enabled('firstTest')// trueSimpleFeature::disabled('firstTest')// falseSimpleFeature::allEnabled(['firstTest','secondTest'])// trueSimpleFeature::allDisabled(['thirdTest','fourthTest'])// trueSimpleFeature::allEnabled(['firstTest','thirdTest'])// falseSimpleFeature::allDisabled(['firstTest','thirdTest'])// false
The package comes with two middlewares that allow to check whether a given set of features is enabled or disabled.
// FEATURE_REGISTRATION=true// FEATURE_ON_PREMISE=trueRoute::get('/register', [RegistrationController::class,'create'])->middleware('feature.enabled:registration');Route::get('/billing', [BillingController,'show'])->middleware('feature.disabled:onPremise');
If the feature hasn't the desired state the middleware will abort the request with a 404.
Furthermore, you can use conditional Blade directives to render content based on the state of a given feature flag.
@feature('registration') <ahref="/register">Register</a>@endfeature
@unlessfeature('onPremise')...@endunlessfeature
composertest
Please seeCHANGELOG for more information on what has changed recently.
Please seeCONTRIBUTING for details.
If you discover any security-related issues, please emailsecurity@rescaled.de instead of using the issue tracker.
The MIT License (MIT). Please seeLicense File for more information.
About
This package aims to provide a fully-featured, yet simple feature flag configuration through environment variables for Laravel 8+