Laravel-Feature-Flags is a package which aims to add simple and easy to use feature flagging functionality to Laravel.
Feature flagging is a way to enable and disable features in your application.
For example:
- Push your new feature to production but enable it at a moment in the future
- Enable new features for small set of users
This package allows you to define a feature and
- enable or disable it globally
- enable or disable it for any type of model in your application
You can install the package via composer:
composer require codegaudi/laravel-feature-flags
You can publish and run the migrations with:
php artisan vendor:publish --provider="Codegaudi\LaravelFeatureFlags\LaravelFeatureFlagsServiceProvider" --tag="migrations"
php artisan migrate
First of all you have to define a new feature. This can be done using the Feature
facade.
use Codegaudi\LaravelFeatureFlags\Facades;
Feature::add($name = 'my-feature', $isEnabled = true);
You can also get the underlying eloquent model.
use Codegaudi\LaravelFeatureFlags\Facades;
Feature::findByName('my-feature');
You can enable or disable them using the following methods.
use Codegaudi\LaravelFeatureFlags\Facades;
Feature::enable('my-feature');
Feature::disable('my-feature');
You can check if a feature is enabled using the isEnabled
and isDisabled
methods.
Feature::isEnabled('my-feature');
Feature::isDisabled('my-feature');
To remove the feature from your application, simpy call the remove
method.
Feature::remove('my-feature');
Of course you can add features to a model. You need to add the HasFeatures
trait to the class of your choice
use Codegaudi\LaravelFeatureFlags\Traits\HasFeatures;
class User extends Model
{
use HasFeatures;
}
Next, enable the feature using the enableFeature
method.
$user = User::first();
$user->enableFeature(Feature::findByName('my-feature'));
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.