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.
isEnabled(string $feature): bool
: Checks if a feature is enabled.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
}
Configuration: Define feature toggles in the feature-toggles.php configuration file. You can specify global settings and override them per-user or per-environment.
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
]
];
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.
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.