2017 © Pedro Peláez
 

library laravel-simple-featureflag

A quick and dirty feature flag for Laravel

image

jtgrimes/laravel-simple-featureflag

A quick and dirty feature flag for Laravel

  • Friday, June 16, 2017
  • by jtgrimes
  • Repository
  • 1 Watchers
  • 0 Stars
  • 190 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

laravel-simple-featureflag

Latest Version on Packagist ![Software License][ico-license] Build Status [![Quality Score][ico-code-quality]][link-code-quality], (*1)

This package gives you a quick and dirty way to use feature flags in Laravel 5+. It doesn't provide configuration by user, nor is it set up for A/B tests. It's a simple on/off switch., (*2)

Install

Install the package with Composer:, (*3)

``` bash $ composer require JTGrimes/laravel-simple-featureflag, (*4)


You'll need to update the providers array in `config/app.php` with the service provider for this package: ```php 'providers' => [ ... JTGrimes\FeatureFlag\ServiceProvider::class, ];

Finally, you'll need to publish the configuration file: You can publish the migration with:, (*5)

``` bash $ php artisan vendor:publish --provider="JTGrimes\FeatureFlag\ServiceProvider", (*6)

## Configuration

The default configuration file is shown below. The array keys are the names of the features
that you're using feature flags for and the values are true/false based on whether the 
feature is enabled. (My convention is to set a FEATURE_* .env variable to 'on' or 'off',
but any expression which is truthy will work.) Any feature which is not found in the config
file will default to being enabled.
```php
return [
    'something' => (env('FEATURE_SOMETHING', 'on') == 'on'),
    'something_else' => (env('SOME_OTHER_FEATURE', 'on') == 'on'),
    'one_more' => false,
];

Usage

The package provides a helper function. To determine whether a feature is enabled, you can call the feature() function from anywhere in your code. ``` php $permitAccess = feature('name');, (*7)

I often find myself using this function in middleware to prevent access to pages which
aren't available yet ... 
```php
        if (!feature('v2')) {
            if (str_contains($request->getUri(), 'v2')) {
                abort(Response::HTTP_NOT_FOUND);
            }
        }
        return $next($request);

There are also helpers for your Blade views:, (*8)

@ifFeature ('test')
    Feature on
@else
    Feature off
@endif

@else is optional, but you must include @endif to close the if statement., (*9)

Change log

Please see CHANGELOG for more information on what has changed recently., (*10)

Testing

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*12)

Security

If you discover any security related issues, please email jtgrimes@gmail.com instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

16/06 2017

dev-master

9999999-dev https://github.com/JTGrimes/laravel-simple-featureflag

A quick and dirty feature flag for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel feature flag laravel-simple-featureflag