Laravel A/B Testing and Feature Flag Package


July 6th, 2022

Laravel A/B Testing and Feature Flag Package

The Laravel A/B Test package helps you quickly set up A/B tests and feature flags in a Laravel app. The package uses the self-hosted ABRouter service (which also has paid hosted options) to power the A/B and feature flag settings.

Here's an example controller using this package to A/B test UI features, in this case, a button color:

use Abrouter\Client\Client;
class ExampleController
public function __invoke(Client $client)
$userId = auth()->user()->id;
$buttonColor = $client->experiments()->run($userId, 'button_color');
return view('button', [
'color' => $buttonColor->getBranchId(),

Another useful feature is feature flags, which help you roll experimental/new features out to customers incrementally, toggling on/off without a code redeploy:

$isEnabledButton = $client->featureFlags()
view('featureFlags', [
'enabledButtonFeatureFlag' => $isEnabledButton,

You'll need to set up the ABRouter service to use this package. You can learn more about this service from the ABRouter Docs. You can learn about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

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