Feature Toggle Utility

The FeatureToggleUtil in the LaraUtilX package provides functionality for enabling or disabling features based on configuration settings, with support for per-user or per-environment overrides.

Methods

  1. isEnabled(string $feature): bool: Checks if a feature is enabled.

Usage

  1. Check Feature Status: To check if a feature is enabled, use the isEnabled method:

    use omarchouman\LaraUtilX\Utilities\FeatureToggleUtil;
    
    if (FeatureToggleUtil::isEnabled('my_feature')) {
       // Feature is enabled
    } else {
       // Feature is disabled
    }
  2. Configuration: Define feature toggles in the feature-toggles.php configuration file. You can specify global settings and override them per-user or per-environment.

  3. Override Feature Status: You can override feature status for specific users or environments by adding entries in the feature-toggles.php configuration file under the respective keys.

    // feature-toggles.php
    return [
        'my_feature' => true,
        'my_feature' => [
            'user.1' => false, // Disable for user with ID 1
            'environment.local' => true, // Enable in local environment
        ]
    ];

Result

The utility returns a boolean value indicating whether the feature is enabled or disabled. It also supports per-user or per-environment overrides, providing flexibility in feature management.

Publish Config

You can publish the feature-toggles config file through the below command:

php artisan vendor:publish --tag=lara-util-x-feature-toggles


This utility simplifies feature toggling, allowing for easy control over feature availability based on configuration settings.