Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created January 8, 2024 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/c285645c60735d810dde3d0dae23b574 to your computer and use it in GitHub Desktop.
Save ziadoz/c285645c60735d810dde3d0dae23b574 to your computer and use it in GitHub Desktop.
Laravel - Feature Flag Packages

Feature Flag Laravel Packages

Disable auto-discovery of the package in your composer.json file:

"extra": {
    "laravel": {
        "dont-discover": [
            "package-namespace/package-name"
        ]
    }
}

Then in your App\Providers\AppServiceProvider class, add the check inside the register() method:

if (featureIsEnabled('package-name')) {
    $this->app->register(\Path\To\PackageServiceProvider::class);
}

Link: https://mattstauffer.com/blog/conditionally-loading-service-providers-in-laravel-5/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment