Laravel 8 可变依赖标记
2021-07-16 17:32 更新
有时,一个类可能具有可变的依赖关系,该依赖关系被类型提示为给定的类(Report ... $reports)。使用 needs 和 giveTagged 方法,您可以轻松地为给定依赖项注入带有该标签的所有容器绑定:
$this->app->when(ReportAggregator::class)
->needs(Report::class)
->giveTagged('reports');以上内容是否对您有帮助:

免费 AI IDE


更多建议: