Home > Back-end >  Prevent a package from including the provider definition of the embedded composer.json
Prevent a package from including the provider definition of the embedded composer.json

Time:02-05

I have a use case where I want to extend a certain package by using my own service provider as well as extending the provided command.

The package has a composer.json definition as follows:

"extra": {
    "laravel": {
      "providers": ["BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider"],
      "aliases": {
        "WebSocketRouter": "BeyondCode\\LaravelWebSockets\\Facades\\WebSocketRouter"
      }
    }
  }

I want laravel to ignore the providers definition without modifying the package.

Does anyone know if that is actually possible?

CodePudding user response:

This can be done by opting out of package discovery.

As a consumer of a package, you can add the following to your composer.json file to selectively opt out of package discovery.

"extra": {
    "laravel": {
        "dont-discover": [
            "beyondcode/laravel-websockets"
        ]
    }
},

This way, the package's service provider will be available to extend your own but won't be automatically loaded.

  •  Tags:  
  • Related