PHP code example of amirhf1 / feature-toggle

1. Go to this page and download the library: Download amirhf1/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/ */

    

amirhf1 / feature-toggle example snippets


use FeatureToggle;

if (FeatureToggle::isEnabled('comments')) {
    // Show comments section
} else {
    // Hide comments section
}

use FeatureToggle;

// Enable a feature
FeatureToggle::enable('new_dashboard');

// Disable a feature
FeatureToggle::disable('registration');

   Route::get('/new-dashboard', function () {
       // New Dashboard Logic
   })->middleware('feature:new_dashboard');
   



use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class FeatureToggleSeeder extends Seeder
{
    public function run()
    {
        DB::table('features')->insert([
            ['name' => 'registration', 'enabled' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'comments', 'enabled' => false, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'new_dashboard', 'enabled' => false, 'created_at' => now(), 'updated_at' => now()],
            // Add more features as needed
        ]);
    }
}
bash
php artisan vendor:publish --provider="amirhf1\FeatureToggle\FeatureToggleServiceProvider" --tag="config"
php artisan vendor:publish --provider="amirhf1\FeatureToggle\FeatureToggleServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan db:seed --class=FeatureToggleSeeder