Get url parameter from Service Provider in Laravel

前端 未结 1 1457
后悔当初
后悔当初 2021-01-17 00:26

Normally in Laravel you get a request bag with all parameters in it. But in a service provider this is not the case. But we do have the request() object.

相关标签:
1条回答
  • 2021-01-17 01:05

    Both boot() and register() methods of any service provider are called before request is parsed and request parameters are known, that's why you can't access them.

    Service providers are supposed to register services and shouldn't depend on the request context. If you want to use request parameters in your services, declare request service as a dependency of your service so that it's injected the moment your service gets instantiated.

    0 讨论(0)
提交回复
热议问题