Home > Enterprise >  How we can have dependency injection in laravel package
How we can have dependency injection in laravel package

Time:04-12

I develop the Laravel package and I want to use Repository Pattern and put services in it and then inject this Repository to my Controller.

Pay attention that I need a solution in package development.

CodePudding user response:

you may define the provider in the extra section of your package's composer.json file. In addition to service providers, you may also list any facades you would like to be registered:

"extra": {
    "laravel": {
        "providers": [
            "Barryvdh\\Debugbar\\ServiceProvider"
        ],
        "aliases": {
            "Debugbar": "Barryvdh\\Debugbar\\Facade"
        }
    }
},

source: https://laravel.com/docs/9.x/packages#package-discovery

  • Related