0

is it possible to pass parameters to a class inside app()->make in bind?

// MyServiceProvider.php (extends 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)
   )
});

I have try makeWith but still i got this error: Unresolvable dependency resolving [Parameter #0 [ $apiKey ]] in class SendGrid

$this->app->bind('MyService', function ($app) {
   return new MyService(
      $app->make('Carbon'),
      $app->makeWith('SendGrid', ['apiKey' => '123'])
   )
});

How can I do that? Thanks in advance.

1 Answer 1

0

I solved the problem. First you have to register a service provider with sendgrid and THEN add the sendgrid service provider in the MyServiceProvider.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.