Laravel A/B Testing and Feature Flag Package
Published on by Paul Redmond
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() ->run('enabled_button_feature_flag'); 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.