0
我创建了一个名为Provider
Laravel工厂模式问题
class Provider
{
private $provider;
public function __construct(ProviderInterface $provider)
{
$this->provider = $provider;
}
}
类在工厂类,我有这样的:
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)]);
}
}
}
当调用ProviderFactory::adapt($request->provider)
我得到一个错误:
Target [App\Services\ProviderInterface] is not instantiable while building [App\Services\Provider].
如果我理解正确,我需要bind()
逻辑,因为它需要知道什么是双nd到ProviderInterface
。我需要在服务提供商中添加bind()
逻辑吗?