PHP Classes

How to Implement Laravel Feature Flags to Control Laravel Application Features Using the Package Feature Flag: Enable and disable features of Laravel application

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-06-17 (3 months ago) RSS 2.0 feedNot enough user ratingsTotal: 10 This week: 1All time: 11,412 This week: 44Up
Version License PHP version Categories
feature-flag 1.0.0Custom (specified...7Libraries, Testing, PHP 7
Description 

Author

This package can enable and disable features of the Laravel application.

It provides a class to store the details of features of a Laravel application, such as the feature name, description, users that have the feature enabled, period of availability of the feature, etc...

The class can check if a given feature is currently enabled.

Features can be enabled and disabled with Artisan.

Innovation Award
PHP Programming Innovation award nominee
June 2024
Number 6
Many applications have features that provide benefits to the application users.

When a feature is implemented, it is a good practice to test it well, eventually with a group of users.

This package allows testing features of Laravel applications restricting access to each feature to a group of users.

The control of enabled features can be done using the Artisan tool.

Manuel Lemos
Picture of Mohamed Ahmed
  Performance   Level  
Name: Mohamed Ahmed <contact>
Classes: 2 packages by
Country: Egypt Egypt
Age: ???
All time rank: 452953 in Egypt Egypt
Week rank: 6 Up1 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 2x

Instructions

Usage

  //Feature Flagging can be simple done by creating the flag
  $featureFlag = new FeatureFlag([
          'name' => 'test',
          'description' => 'Test feature flag',
      ]);
  $featureFlag->save();

  //using the flag to scope your your code using if condition or any other way you like
  if ($featureFlag->isEnabled()) {
      // Implement the feature for the user
  }

  //or you can use the method Targted and checking the audience to match to specific audience
  if($featureFlag->isTargeted() && in_array($user->id, $featureFlag->getAudience())) {
      // Implement the feature for the user
  }

  //Feature Flagging can be also used to target users based on percentage
  $featureFlag = new FeatureFlag([
          'name' => 'test',
          'description' => 'Test feature flag',
          'percentage'=>50
      ]);
  $featureFlag->save();
  // you can use the method isEnabledForUser and checking the audience to match to specific audience i.e 50%
  if($featureFlag->isEnabledForUser($user)) {
      // Implement the feature for the user
  }
  //Feature Flagging can be also used to flag based on datetime 
  $featureFlag = new FeatureFlag([
          'name' => 'test flag',
          'finish_date' => '01/04/2023',
          'enabled' => true,
      ]);
  $featureFlag->save();
  // you can use the env either to throw an exception or send a notification when flag expires
  if($featureFlag->isEnabled()) {
      // Implement the feature for the user
  }
  //then simply call feature-flag:manage followed by the name of your flag to enable Or disable it 
  php artisan feature-flag:manage {flag : The name of the feature flag} 
  {--enable : Enable the feature flag} {--disable : Disable the feature flag}
  Files folder image Files (24)  
File Role Description
Files folder image.github (1 directory)
Files folder imageconfig (1 file)
Files folder imagesrc (2 files, 6 directories)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .env.testing Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Image file logo.png Icon Icon image
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (24)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (24)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file main.yml Data Auxiliary data

  Files folder image Files (24)  /  config  
File Role Description
  Accessible without login Plain text file config.php Aux. Configuration script

  Files folder image Files (24)  /  src  
File Role Description
Files folder imageconfig (1 file)
Files folder imageConsole (1 file)
Files folder imageInterfaces (1 file)
Files folder imageMigrations (3 files)
Files folder imageModels (1 file)
Files folder imageNotifications (1 file)
  Plain text file FeatureFlagFacade.php Class Class source
  Plain text file FeatureFlagServiceProvider.php Class Class source

  Files folder image Files (24)  /  src  /  config  
File Role Description
  Accessible without login Plain text file config.php Aux. Configuration script

  Files folder image Files (24)  /  src  /  Console  
File Role Description
  Plain text file ManageFeatureFlagsCommand.php Class Class source

  Files folder image Files (24)  /  src  /  Interfaces  
File Role Description
  Plain text file FeatureFlagInterface.php Class Class source

  Files folder image Files (24)  /  src  /  Migrations  
File Role Description
  Plain text file 2018_08_08_00000_c...ure_flags_table.php Class Class source
  Plain text file 2018_08_09_00000_a...ure_flags_table.php Class Class source
  Plain text file 2018_08_10_00000_a...ure_flags_table.php Class Class source

  Files folder image Files (24)  /  src  /  Models  
File Role Description
  Plain text file EloquentFeatureFlag.php Class Class source

  Files folder image Files (24)  /  src  /  Notifications  
File Role Description
  Plain text file ExpiredFeatureFlagNotification.php Class Class source

  Files folder image Files (24)  /  tests  
File Role Description
Files folder imageFeature (2 files)
  Plain text file TestCase.php Class Class source

  Files folder image Files (24)  /  tests  /  Feature  
File Role Description
  Plain text file EloquentFeatureFlagTest.php Class Class source
  Plain text file FeatureFlagCommandTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:10
This week:1
All time:11,412
This week:44Up