PHP code example of chemaclass / laravel-feature-flags
1. Go to this page and download the library: Download chemaclass/laravel-feature-flags 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/ */
chemaclass / laravel-feature-flags example snippets
use Chemaclass\FeatureFlags\Contracts\FeatureKey;
use Chemaclass\FeatureFlags\Facades\FeatureFlag;
enum AppFeature: string implements FeatureKey
{
case NewDashboard = 'new-dashboard';
public function key(): string { return $this->value; }
}
// Global check
if (FeatureFlag::isEnabled(AppFeature::NewDashboard)) {
// gated code
}
// Scoped check. $scopeId is whatever string your app decides on
// (team id, organization id, region code, cohort name, etc.)
if (FeatureFlag::isEnabled(AppFeature::NewDashboard, $scopeId)) {
// gated code
}
use Chemaclass\FeatureFlags\Http\Middleware\EnsureFeatureIsActive;
Route::get('/dashboard', DashboardController::class)
->middleware(EnsureFeatureIsActive::using(AppFeature::NewDashboard));
// or via alias
Route::get('/dashboard', DashboardController::class)
->middleware('feature.enabled:new-dashboard');