Enabling / Disabling Features in a Laravel App

This is technically called feature flags - https://martinfowler.com/articles/feature-toggles.html

depends on your requirements, flags in config/database, rollout, etc...

But it's basically if's in code and cannot be clean.

Laravel packages:

https://github.com/alfred-nutile-inc/laravel-feature-flag

https://github.com/francescomalatesta/laravel-feature

Some services:

https://launchdarkly.com/

https://bullet-train.io/

https://configcat.com/

Also look at https://marketingplatform.google.com/about/optimize/ for frontend.


I've encountered the same problem when I tried to implement multiple hotel providers.

What I did was using service container.

first you will create class for each domain With his features:

  • like Doman1.php ,Domain2.php
  • then inside each one of those you will add your logic.

then you gonna use binding in your app service provider to bind the domain with class to use.

$this->app->bind('Domain1',function (){
       return new Domain1();
    });
    $this->app->bind('Domain2',function (){
        return new Domain2();
    });

Note you can use general class that holds the features goes with all domains then use that general class in your classes

Finally in your controller you can check your domain then to use the class you gonna use

    app(url('/'))->methodName();