1. Go to this page and download the library: Download ericdowell/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/ */
ericdowell / feature-toggle example snippets
if (feature_toggle_api()->isActive('Example')) {
// do something
}
if (feature_toggle('Example')) {
// do something
}
if (feature_toggle('Example', false)) {
// do something when toggle is inactive
}
// OR
if (feature_toggle('Example', 'off')) {
// do something when toggle is inactive
}
use Illuminate\Support\Facades\Route;
// Passing all three parameters, changing abort to 403 status code.
Route::get('user/billing')->middleware('featureToggle:subscription,true,403')->uses('User\\BillingController@index')->name('billing.index');
// Passing two parameters.
Route::get('user/subscribe')->middleware('featureToggle:subscription,true')->uses('User\\SubscribeController@index')->name('subscribe.index');
// Passing just the name.
Route::get('user/trial')->middleware('featureToggle:trial')->uses('User\\TrialController@index')->name('trial.index');
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly()
->when(feature_toggle('Inspire Command'));
}
}
use Illuminate\Support\Facades\Validator;
Validator::make(request()->all(), [
'phone' => ',
]);
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
Validator::make(request()->all(), [
'phone' => Rule::
use FeatureToggle\Facades\FeatureToggleApi;
use Illuminate\Support\Facades\Validator;
Validator::make(request()->all(), [
'phone' => FeatureToggleApi::
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
// calling conditional function is deferred by default
feature_toggle_api()->setConditional('Example', function (Request $request) {
$user = $request->user();
return $user instanceof \App\User && $user->email === '[email protected]';
});
// OR call right away by passing false as $defer parameter
feature_toggle_api()->setConditional('Example', function () {
return Cache::get('feature:example');
}, false);