PHP code example of dive-be / laravel-feature-flags
1. Go to this page and download the library: Download dive-be/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/ */
dive-be / laravel-feature-flags example snippets
return [
/**
* The name of the cache key that will be used to cache your app's features.
*/
'cache_key' => 'feature_flags',
/**
* The feature model that will be used to retrieve your app's features.
*/
'feature_model' => Dive\FeatureFlags\Models\Feature::class,
];
use Dive\FeatureFlags\Models\Feature;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class FeaturesTableSeeder extends Seeder
{
public function run()
{
DB::table('features')->upsert([
[
'description' => 'Registrations that come through our partnerships',
'label' => 'Public registrations',
'message' => 'The registration period has ended. Thanks for participating in our programme.',
'name' => 'registrations',
'scope' => Feature::getDefaultScope(),
],
[
'description' => 'Display the App version on the homepage',
'label' => 'Application version',
'message' => 'Version is hidden',
'name' => 'version',
'scope' => Feature::getDefaultScope(),
],
], ['scope', 'name'], ['description', 'label', 'message']);
}
}
use Dive\FeatureFlags\Facades\Feature;
Feature::find('dashboard');
use Dive\FeatureFlags\Contracts\Feature;
public function index(Feature $feature)
{
$feature->verify('dashboard');
return view('layouts.dashboard');
}
app('feature')->find('dashboard');
use Dive\FeatureFlags\Models\Feature;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Feature::setDefaultScope('my-wonderful-app');
}
}
@can('feature', 'dashboard')
<a href="/dashboard" target="_blank">View Dashboard</a>
@else
<small>Dashboard is currently disabled</small>
@endcan
class RegistrationsController extends Controller
{
public function __construct(Feature $feature)
{
$feature->verify('registrations');
}
public function index()
{
return view('registrations.index');
}
}
use Dive\FeatureFlags\Facades\Feature;
use Dive\Wishlist\Facades\Wishlist;
class HeartButton extends Component
{
public function add($id)
{
Feature::verify('wishlist');
Wishlist::add($id);
}
public function render()
{
return view('livewire.heart-button');
}
}