I have created a class called Provider
class Provider
{
private $provider;
public function __construct(ProviderInterface $provider)
{
$this->provider = $provider;
}
}
In the factory class, I have like this:
class ProviderFactory
{
public static function adapt(string $provider)
{
switch ($provider) {
case 'ProviderOne':
return app(Provider::class, [app(ProviderOne::class)]);
case 'ProviderTwo':
return app(Provider::class, [app(ProviderTwo::class)]);
}
}
}
When calling ProviderFactory::adapt($request->provider) I get an error:
Target [App\Services\ProviderInterface] is not instantiable while building [App\Services\Provider].
If I understand correctly I need bind() logic as it needs to know what to bind to the ProviderInterface. Do I need add bind() logic in the service provider?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire