PHP code example of al_imran / runtime-feature-toggle
1. Go to this page and download the library: Download al_imran/runtime-feature-toggle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
al_imran / runtime-feature-toggle example snippets
// config/feature.php
'routes' => [
'prefix' => 'admin/features', // Change the URL prefix if desired
'middleware' => ['web', 'auth', 'can:manage-features'], // Add your protection here
],
use Imran\RuntimeFeatureToggle\Facades\Feature;
// Via Facade
if (Feature::enabled('new_checkout_flow')) {
// Show the new checkout
}
// Via Helper
if (feature('new_checkout_flow')->enabled()) {
// Show the new checkout
}
// Returns the JSON payload from the DB.
// If the feature is missing, it returns null.
// If the feature exists but its value is empty, it returns the default (50).
$limit = Feature::value('upload_limit', 50);
// Helper syntax
$config = feature('theme_colors')->value(['primary' => '#000']);
$user = auth()->user();
if (Feature::enabled('beta_access', $user)) {
// This user specifically has access based on rules defined in the dashboard
}
// In a ServiceProvider
Feature::extend('user_level', function ($context, $value) {
return $context->level >= $value;
});
public function test_new_feature_is_displayed()
{
Feature::fake([
'new_feature' => true,
'api_limit' => 1000
]);
$this->get('/dashboard')->assertSee('New Feature');
}