Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I opt out of package discovery for a specific package in Laravel 11


How do I opt out of package discovery for a specific package in Laravel 11


To opt out of package discovery for a specific package in Laravel 11, you can add the package name to the `dont-discover` array in the `extra` section of your application's `composer.json` file:

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

Replace `vendor/package-name` with the actual vendor and package name you want to opt out of discovery for.

For example, to disable package discovery for the `barryvdh/laravel-debugbar` package, you would add:

json
"extra": {
    "laravel": {
        "dont-discover": [
            "barryvdh/laravel-debugbar"
        ]
    }
}

After making this change, run `composer update` to apply the changes.

By opting out of package discovery, you will need to manually register the service providers and facades for that package in your application's `config/app.php` file:

php
'providers' => [
    // ...
    Vendor\Package\PackageServiceProvider::class,
],

'aliases' => [
    // ...
    'PackageFacade' => Vendor\Package\Facade::class,
],

This gives you more control over which packages are loaded and in what order, but requires more manual configuration[1][3].

Citations:
[1] https://laravel.com/docs/11.x/packages
[2] https://docs.cornch.dev/en/laravel/8.x/packages
[3] https://www.bacancytechnology.com/qanda/laravel/disable-providers-from-package-discovery
[4] https://github.com/laravel/ideas/issues/784
[5] https://github.com/spatie/laravel-package-tools/blob/main/src/PackageServiceProvider.php