Feature Flags for Laravel

News

August 8th, 2019

The Feature Flags package for Laravel by Peter Fox helps you handle Feature Toggles (aka Feature Flags) in your Laravel applications:

A Feature flag is sometimes also referred to as a feature toggle or feature switch. Ultimately it’s a coding strategy to be used along with source control to make it easier to continuous integrate and continuous deployment. The idea of the flags works by essentially safe guarding sections of code from executing if a feature flag isn’t in a switched on state.

This package aims to make implementing such flags across your application a great deal easier by providing solutions that work with not only your code but your routes, blade files, task scheduling and validations.

This package provides configuration with multiple storage options, and helps you in various contexts:

  • Blade Views
  • Routing Middleware
  • Validation Rules
  • Task Scheduling
  • Artisan Commands
  • Custom PHP logic

With this package you can use the provides Features facade or service to do things like check if a feature is on or off:

Features::accessible('my-feature') // returns true or false

The same check within a blade template would look like the following:

@feature('my-feature')
    <p>Your feature flag is turned on.
@endfeature

@feature('my-feature', false)
    <p>Your feature flag is turned off.
@endfeature

Using the same feature name, you could toggle a route on/off using the provided middleware:

Route::get('/', 'SomeController@get')
    ->middleware('feature:my-feature');

You can learn more about this package, get full installation instructions, and view the source code on GitHub at ylsideas/feature-flags.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.