Simple Feature allows you to define feature flags via environment variables and check for their state within your 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 with FEATURE_
.
FEATURE_FIRST_TEST=true
FEATURE_SECOND_TEST=true
FEATURE_THIRD_TEST=false
FEATURE_FOURTH_TEST=false
You can directly access the package's methods as following.
SimpleFeature::enabled('firstTest') // true
SimpleFeature::disabled('firstTest') // false
SimpleFeature::allEnabled(['firstTest', 'secondTest']) // true
SimpleFeature::allDisabled(['thirdTest', 'fourthTest']) // true
SimpleFeature::allEnabled(['firstTest', 'thirdTest']) // false
SimpleFeature::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=true
Route::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')
<a href="/register">Register</a>
@endfeature
@unlessfeature('onPremise')
...
@endunlessfeature
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email security@rescaled.de instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.