PHP Laravel

Install PHP Laravel SDK

You can find the latest version on our github Repository:

Install our Switchover Laravel SDK ina aexisting Laravel App using composer:

composer require switchover/laravel-integration

Add your SDK Key.

You will find your SDK Key on the environment page. Copy it and add it in the .env to initialize the client:


and configure the caching time:

SWITCHOVER_CACHE_TIME=10 # Warning: 0 will cache forever

After that you can use Switchover on any place using:

use SwitchoverLaravel\Switchover;
use Switchover\Context;

Basic usage example

Basic usage:

class HomeController extends Controller

    public function index() {

        $userCtx = new Context([
            'email' => Auth::user()->email;
        $coolNewFeatures = Switchover::toggleValue('cool-feature', false, $userCtx);

        return //...

You can also publish the underlying config file to get full control over the config e.g. for the Guzzle Http client:

php artisan vendor:publish --tag="switchover-config"

After that, you will find the configuration in your app/config folder

Blade directive

Of course we also offer an extension to use Feature Toggles directly in Blade Templates. There are two ways to use them:

@hasFeatureuse it to check boolean flags in your blade tempate
@hasConditionalFeatureuse it if you have also conditional values configured

both directives ends on @endHasFeature


<body class="myawesomeClass">
           Your content will be shown

<body class="myawesomeClass">
        @hasConditionalFeature("yourToggleName",["email" => ""])
           Your content will be shown



cache.timeSets time in seconds before the internal cache becomes stale and will be refreshed (TTL). Default is 60 seconds. The value 0 will keep the cache forever.
httpThe client uses guzzlehttp/guzzle for http requests. You can pass an array of options to the Guzzle Http Client.

Context Object

To check conditions in the client sdk a context object must be created and passed to the toggleValue method.

$contextArray = array("key" => "value");
$context = new Context($contextArray);

Public methods


namethe name of the feature toggle configured in switchover
defaultValueIt will return the given default value:
* – When toggle is INACTIVE
* – When evalution fails
* – When client was not fully initialized
contextContext Object (array)
    string $name, 
    boolean $defaultValue, 
    Context $context = null


Manually refreshes toggles.



Get all toggle keys, which currently loaded