PHP code example of evolabs / laravel-feature-flags

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

    

evolabs / laravel-feature-flags example snippets


use Evolabs\FeatureFlags\Models\Feature;
use Illuminate\Database\Seeder;

class FeaturesTableSeeder extends Seeder
{
    public function run()
    {
        Feature::query()->create(['name' => 'information_pages'];
        Feature::query()->create(['name' => 'locale_change', 'group' => 'admin'];
    }
}

Features::isAccessible('information_pages')

Route::get('/', 'YourController@index')->middleware('feature:information_pages')

namespace Evolabs\FeatureFlags\DataTransferObjects;

class FeatureData
{
    public function __construct(
        public readonly string $name,
        public readonly ?string $group,
        public readonly bool $is_enabled
    ) {
    }
}

@feature('information_pages')
    <p>Feature flag `information_pages` is turned on.</p>
@endfeature

use Evolabs\FeatureFlags\Facades\Features;
use Illuminate\Http\Request;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    /**
     * The root template that's loaded on the first page visit.
     *
     * @see https://inertiajs.com/server-side-setup#root-template
     *
     * @var string
     */
    protected $rootView = 'admin/app';

    /**
     * Defines the props that are shared by default.
     *
     * @see https://inertiajs.com/shared-data
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function share(Request $request)
    {
        return [
            ...parent::share($request),
            'features' => Features::all('admin')->pluck('is_enabled', 'name')
        ];
    }
}
bash
php artisan vendor:publish --provider="Evolabs\FeatureFlags\FeatureFlagsServiceProvider" --tag=migrations
php artisan migrate
bash
php artisan vendor:publish --provider="Evolabs\FeatureFlags\FeatureFlagsServiceProvider" --tag=config
bash
php artisan feature:on information_pages

php artisan feature:off information_pages