I'm trying to Inject a SoapClient dependency into Foo class, I've made a provider container but I can't resolve the dependency.
This is the class I'm trying to Inject the dependency in.
namespace App\Services
Class Foo{
public function __construct( )
{
$this->SoapClient = resolve('MySoapClient');
}
public function someMethod($data)
{
$req=$this->SoapClient->getSomething($params);
return $req;
}
}
this is the service provider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
use \Illuminate\Foundation\Application;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('MySoapClient', function ($app) {
return new \SoapClient(env('wsdl'));
});
}
}
I just want to inject SoapClient into the Foo class. the above code is not working and I'm getting that( class MySoapClient doesn't exist )