【发布时间】:2019-07-24 20:44:40
【问题描述】:
是否可以将参数传递给 app()->make in bind 中的类?
// MyServiceProvider.php(扩展ServiceProvider)
$this->app->bind('MyService', function ($app) {
return new MyService(
$app->make('Carbon'),
$app->make('SendGrid') // here is where i want to pass some parameters like if I do: new SendGrid($apiKey)
)
});
我尝试过 makeWith 但仍然出现此错误: SendGrid 类中无法解析的依赖解析 [Parameter #0 [ $apiKey ]]
$this->app->bind('MyService', function ($app) {
return new MyService(
$app->make('Carbon'),
$app->makeWith('SendGrid', ['apiKey' => '123'])
)
});
我该怎么做? 提前致谢。
【问题讨论】: