Package Data | |
---|---|
Maintainer Username: | jtgrimes |
Maintainer Contact: | jtgrimes@gmail.com (J.T. Grimes) |
Package Create Date: | 2017-05-23 |
Package Last Update: | 2017-06-16 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-05 03:17:21 |
Package Statistics | |
---|---|
Total Downloads: | 320 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package gives you a quick and dirty way to use feature flags in Laravel 5+. It doesn't provide configuration by user, nor is it set up for A/B tests. It's a simple on/off switch.
Install the package with Composer:
$ composer require JTGrimes/laravel-simple-featureflag
You'll need to update the providers array in config/app.php
with the service provider for this package:
'providers' => [
...
JTGrimes\FeatureFlag\ServiceProvider::class,
];
Finally, you'll need to publish the configuration file: You can publish the migration with:
$ php artisan vendor:publish --provider="JTGrimes\FeatureFlag\ServiceProvider"
The default configuration file is shown below. The array keys are the names of the features that you're using feature flags for and the values are true/false based on whether the feature is enabled. (My convention is to set a FEATURE_* .env variable to 'on' or 'off', but any expression which is truthy will work.) Any feature which is not found in the config file will default to being enabled.
return [
'something' => (env('FEATURE_SOMETHING', 'on') == 'on'),
'something_else' => (env('SOME_OTHER_FEATURE', 'on') == 'on'),
'one_more' => false,
];
The package provides a helper function. To determine whether a feature is enabled,
you can call the feature()
function from anywhere in your code.
$permitAccess = feature('name');
I often find myself using this function in middleware to prevent access to pages which aren't available yet ...
if (!feature('v2')) {
if (str_contains($request->getUri(), 'v2')) {
abort(Response::HTTP_NOT_FOUND);
}
}
return $next($request);
There are also helpers for your Blade views:
@ifFeature ('test')
Feature on
@else
Feature off
@endif
@else
is optional, but you must include @endif
to close the if statement.
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email jtgrimes@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.