Skip to content

codegaudi/laravel-feature-flags

Repository files navigation

Laravel-Feature-Flags

Latest Version on Packagist GitHub Tests Action Status Total Downloads

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.

About

Feature flagging functionality for Laravel

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages