Laravel服务提供商:带参数的新类

时间:2019-03-03 10:42:29

标签: laravel service-provider

是否可以将参数传递给app()-> make in bind中的类?

// MyServiceProvider.php(扩展ServiceProvider)

If ($rowsAffected -ge 1) 
{
    "Your request for the file has been successfully submitted and will be processed in the next few minutes. "
    pause
}
else
{
    "ERROR! No file was found. Please contact support"
    pause
}

我尝试makeWith,但是仍然出现此错误: 类SendGrid中无法解析的依赖项解析[Parameter#0 [$ apiKey]]

$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)
   )
});

我该怎么做? 提前致谢。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。 首先,您必须向sendgrid注册服务提供商,然后在MyServiceProvider.php中添加sendgrid服务提供商。