Guide

How to bring the feature flags to your Laravel project?

ABRouter is a platform that solves products problems and helps to improve conversions and user experience. We focused on the developer experience, finite user experience, and of course, on your business. In this post, we'll talk about the implementation of feature flags in Laravel.

Definition

Common feature flags definition

Feature flags are also known as feature toggles. The feature flags are configurations that allow you to enable or disable some part of your code in your application. So, you can control the specific feature in your app in any environment.
Usually, enabling or disabling is working fast, and changes will take effect immediately, and that's critical nowadays. Technically feature flag looks like a true or false value received by the HTTPS(internet) call or via another transport with the remote server.
Start for free
Use cases

Feature flags use-cases

I hope you're interested in using feature flags. There are the following
reasons to bring it to your Laravel application:
Faster delivery to production.

Sometimes it's the only way to deliver the feature in production. If you're waiting for someone, front end, for example, you have to wait.

While your feature branch is waiting for the deployment, the code could be broken by someone, or someone from your team will change it and throw you into the work with VCS conflicts. Based on my experience, it's better to deploy when your code is fresh.

Only one thing which you and your team have to test carefully when you release the feature flag is the correct isolation of the new code. With the right level of code isolation, you can sleep well and disable your feature flag anytime and then fix it and enable it again.

Change of the highly-important part of the application that always should be controlled.

When you change part of your application the mistake can be too expensive, so the right decision is to care about it early and make the change under the feature flag. Feature flags do not imply any measurement of payments or conversions for the changed code, so it will work faster and perfectly fits this goal.

And the last, but not least is code which shell works time-to-time.

For example, it can be a captcha, rate liming, or email confirmation on the sign-up step. You can enable something from it when your Laravel application is experiencing some kind of additional load.

Task

Plan your first Laravel feature flag

Task definition:
Our task for today is to wrap the two HTML buttons to the feature flag, one enabled and one - disabled.

So, we can turn on or turn off one of the buttons or both anytime. Just the usual if-statements with some additional preparation to start working on the ABRouter platform and basic wiring the client in your Laravel project codebase.

From words to work

Follow the steps, it's easy:
Step 1: Sign-up by the link
Step 2: Create your feature flags.
Step 3: Grab the data

After creating the A/B test you can to get the important data to run it.

Step 4: Install

Install the library to your codebase on PHP:
https://github.com/abrouter/laravel-abtest

This library based on main ABRouter client:
https://github.com/abrouter/abrouter-php-client

This library includes ab-tests and feature flags managing on ABRouter.

  • Install the package:
    composer require abrouter/laravel-abtest

    This package provide auto discovery for service provider. If Symfony package auto-discovery is disabled, add service providers manually in your /app/app.php of your repository.

    There are service providers you must add:

    \Abrouter\LaravelClient\Providers\AbrouterServiceProvider::class

  • Publish client configuration:
    php artisan vendor:publish --tag=abrouter
  • Configure the client:

    There you have to put your ABRouter token from your dashboard which is described in the third point.

Step 5: Code

Now we are ready to code. Also, you can check an example of fully completed code on GitHub: https://github.com/abrouter/laravel-example

Step 6: There is our result

One of the button is displayed and one is hidden under the if statement with turned of feature flag.

On this page
Step 1: Sign-up by the link
Step 2: Create your feature flags.
Step 3: Grab the data
Step 4: Install
Step 5: Code
Step 6: There is our result

Getting started is easy

Deploy with feature flags is not stress anymore
Create your first feature flag

Summary

I have shown you how to implement the feature flag with Laravel framework via ABRouter. Looks like it's quite simple. Please, remember, that huge or uncertain changes, that couldn't be tested with a/b test should be implemented via feature flag to prevent unpredictable situations and save your business.

If you have any questions, feel free to ask me at abrouter@proxiedmail.com or via green "Ask Us" button here.

You're don't need to implement it on your own

Because we already did it in a perfect way in ABRouter open-source platform for A/B testing and feature flags!

Branch memorization & User identifiers association
ABRouter system will keep the user in the same branch after he got it the first time. It’s important to keep the user in the same branch all the time. With user identifiers association we will accept the relations between permanent user id and guest user id and keep the user in the same branch. Make an association through sending both identifiers in single statistic event.
Viewing statistics by branch
We will match the branch with the users events and show you detailed statistics which will help you to decide the better performed branch to make it base line.
Useful UI
We have implemented first-class UI to manage your A/B tests, feature flags and viewing statistics. It will help you to make the important decisions on your product and increase the your product growth.