codegaudi / laravel-feature-flags
laravel-feature-flags
Fund package maintenance!
codegaudi
Installs: 1 121
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0 || ^8.1
- illuminate/contracts: ^9.0 || ^10.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ^7.0 || ^8.0
- phpunit/phpunit: ^9.3 || ^10.0
README
Laravel-Feature-Flags is a package which aims to add simple and easy to use feature flagging functionality to Laravel.
What is feature flagging?
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
Installation
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
Usage
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'));
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.